<?php

namespace Dms\Controller;
use Think\Controller;
class WebproductController extends Controller
{

	public function test()
	{

		$list = M2('order_basics')
				->join('cms_activity_shake_ticket_order ON cms_order_basics.id = cms_activity_shake_ticket_order.orderID')
				->where(array('productType'=>'4','cms_order_basics.status'=>'2'))
				->order('departureDate')
				->select();

		foreach ($list as $key => $value)
		{
			$list[$key]['statusName']        = '已支付';
			$list[$key]['payDate']           = empty($value['payTime']) ? '' : date('Y-m-d H:i:s',$value['payTime']);
			$list[$key]['departureDate']     = date('Y-m-d',$value['departureDate']);
		}


		$objPHPExcel = writeExcel();
	    $sheet = 0;
		$objPHPExcel->setActiveSheetIndex($sheet);
		$objPHPExcel->getActiveSheet()->mergeCells('A1:M1');
		$objPHPExcel->getActiveSheet()->SetCellValue('A1', '10元香港列表');
		$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
		$objPHPExcel->getActiveSheet()->setTitle('列表');
		$objPHPExcel->getActiveSheet()->SetCellValue('A2','订单号');
		$objPHPExcel->getActiveSheet()->SetCellValue('B2','联系人');
		$objPHPExcel->getActiveSheet()->SetCellValue('C2','联系电话');
		$objPHPExcel->getActiveSheet()->SetCellValue('D2','出发日期');
		$objPHPExcel->getActiveSheet()->SetCellValue('E2','出发地');
		$objPHPExcel->getActiveSheet()->SetCellValue('F2','目的地');
		$objPHPExcel->getActiveSheet()->SetCellValue('G2','上车地点');
		$objPHPExcel->getActiveSheet()->SetCellValue('H2','下车地点');
		$objPHPExcel->getActiveSheet()->SetCellValue('I2','支付金额');
		$objPHPExcel->getActiveSheet()->SetCellValue('K2','出行人数');
		$objPHPExcel->getActiveSheet()->SetCellValue('L2','订单状态');
		$objPHPExcel->getActiveSheet()->SetCellValue('M2','支付时间');
	    $i  = 3;

		foreach($list as $key => $value)
		{

			$objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $value['orderCode']);
			$objPHPExcel->getActiveSheet()->SetCellValue('B'.$i, $value['contactName']);
			$objPHPExcel->getActiveSheet()->SetCellValue('C'.$i, $value['contactMobile']);
			$objPHPExcel->getActiveSheet()->SetCellValue('D'.$i, $value['departureDate']);
			$objPHPExcel->getActiveSheet()->SetCellValue('E'.$i, $value['departureName']);
			$objPHPExcel->getActiveSheet()->SetCellValue('F'.$i, $value['destinationName']);
			$objPHPExcel->getActiveSheet()->SetCellValue('G'.$i, $value['getOnAddressName']);
			$objPHPExcel->getActiveSheet()->SetCellValue('H'.$i, $value['getOffAddressName']);
			$objPHPExcel->getActiveSheet()->SetCellValue('I'.$i, $value['price']);
			$objPHPExcel->getActiveSheet()->SetCellValue('K'.$i, $value['nums']);
			$objPHPExcel->getActiveSheet()->SetCellValue('L'.$i, $value['statusName']);
			$objPHPExcel->getActiveSheet()->SetCellValue('M'.$i, $value['payDate']);
			$i++;

		}

		exportExcel($objPHPExcel,'10元香港列表');
	}
    /**
     * [sell description]
     * @return [type] [description]
     */
    public function sell()
    {


		$keyword = I('get.keyword','','trim');
		$status  = I('get.status',0);
		$type    = I('get.type',0);

		$where = array();
		if(empty($keyword) == false)$where['_string'] = '`id` = $keyword OR `title` LIKE %$keyword%';
		if(empty($status) == false)$where['status'] = $status;
		if(empty($keyword) == false)$where['type'] = $type;

		$count = M2('product_new')->where($where)->count();
		$PageClass  = new \Think\Page($count,10);
		$page  = $PageClass->show();
		$list = M2('product_new')->where($where)->limit($PageClass->firstRow.','.$PageClass->listRows)->order(array('status'=>'DESC','id'=>'DESC'))->select();
		foreach ($list as $key => $value)
		{
			switch ($value['class'])
			{
				case '1':
					$list[$key]['className'] = '自由行';
					break;
				case '2':
					$list[$key]['className'] = '当地游';
					break;
			}
		}
		$this->page     = $page;
		$this->list    	= $list;

		$this->menuID   = '152';
		$this->menuName = '直销产品';

    	$this->display();
    }

    /**
     * [selladd description]
     * @return [type] [description]
     */
    public function selladd()
    {

    	if(IS_POST)
		{
			//引入日志类
			$Log       = new \Model\Log();

			$data['title']                = I('post.title');
			$data['verify']               = I('post.verify',1);
			$data['extend']               = I('post.extend');
			$data['special']              = I('post.special',0);
			$data['description']          = I('post.description');
			$data['keyWords']             = I('post.keyWords');
			
			//产品标签
			$labelIDArr                   = I('post.labelID',array());
			
			//主站分类标签
			$categoryID                   = I('post.categoryID');
			$packCategoryTwo              = I('post.packCategoryTwo');
			$categoryLabelArr             = I('post.categorylabel',array());
			
			//进销存产品绑定
			$libraryIDArr                 = I('post.libraryID',array());
			$addPriceTypeArr              = I('post.addPriceType',array());
			$addPriceNumsArr              = I('post.addPriceNums',array());
			
			//目的地
			$areaIDArr                    = I('post.areaID',array());
			$countryIDArr                 = I('post.countryID',array());
			$cityIDArr                    = I('post.cityID',array());
			
			$data['travelDays']           = I('post.travelDays');
			$data['travelNight']          = I('post.travelNight');
			$data['marketPrice']          = I('post.marketPrice');
			$data['sellPrice']            = I('post.price');
			
			$data['thumbImages']          = I('post.thumbImages');
			$originalImages               = I('post.originalImages');
			$data['originalImagesPC']     = $originalImages;
			$pathArr = explode('/',$originalImages);
			$imgname = end($pathArr);

			$originalImagesMobile = str_replace($imgname,'mobile_'.$imgname,$originalImages);

			if( !@fopen( $originalImagesMobile , 'r' ) )
		    {
		    	$arr = explode('.',$imgname);

		        $dataPost = array(
            		'ext'=>$arr[1],
            		'saveName'=>$imgname,
            		'savePath'=>str_replace('http://www.tripvip.cn/Upload/','',str_replace($imgname,'',$originalImages)),
            		'randNums'=>substr($arr[0],0,6)
        		);

            	$ch = curl_init ();
				curl_setopt ( $ch, CURLOPT_URL, 'http://www.tripvip.cn/center/public/cropBigPic' );
				curl_setopt ( $ch, CURLOPT_POST, 1 );
				curl_setopt ( $ch, CURLOPT_HEADER, 0 );
				curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
				curl_setopt ( $ch, CURLOPT_POSTFIELDS, $dataPost );
				$mobileUrl = curl_exec ( $ch );
				curl_close ( $ch );
		    }
		    $data['originalImagesMobile'] = 'http://www.tripvip.cn'.$mobileUrl;
		    
			$data['class']                = '1';
			$data['createTime']           = time();
			$data['adduserID']            = getIdenty();

			$productID = M3('product_new')->add($data);
			
			$Log->webproductOperation($productID,M3('product_new')->getLastSql());
			if($productID)
			{

				$libraryIDCount = count($libraryIDArr);
				for ($i=0; $i < $libraryIDCount; $i++)
				{

					$library = M2('library')->field('id,name,class,destinationContinent,destinationCountry,destinationCity,departureCity')->where(array('productID'=>$libraryIDArr[$i]))->find();
					$product_line_libraryData['productID']    = $productID;
					$product_line_libraryData['libraryID']    = $library['id'];


					$product_line_libraryData['libraryTitle'] = $library['name'];
					$product_line_libraryData['departureID']  = $library['departureCity'];

					$product_line_libraryData['areaID']       = $library['destinationContinent'];
					$product_line_libraryData['countryID']    = $library['destinationCountry'];
					$product_line_libraryData['cityID']       = $library['destinationCity'];
					$product_line_libraryData['gainType']     = $addPriceTypeArr[$i];
					switch ($addPriceTypeArr[$i])
					{
						case '0':
							$product_line_libraryData['gainNums'] = 0;
							break;

						default:
							$product_line_libraryData['gainNums']  = $addPriceNumsArr[$i];
							break;
					}


					M3('product_library_new')->add($product_line_libraryData);
					
					$Log->webproductOperation($productID,M3('product_library_new')->getLastSql());
					switch ($addPriceTypeArr[$i])
					{
						case '0':
							$library_time = M2('library_time')->where(array('libraryID'=>$library['id'],'departureTime'=>array('egt',time()),'stockNow'=>array('gt','0')))->select();
							foreach ($library_time as $key => $value)
							{
								if($value['adultCostPrice'] != false)
								{
									$departureDateData['productID']     = $productID;//................产品ID
									$departureDateData['libraryID']     = $library['id'];//................libraryID
									$departureDateData['departureID']   = $library['departureCity'];
									$departureDateData['departureTime'] = $value['departureTime'];
									$departureDateData['adultPrice']    = $value['adultCostPrice'];
									$departureDateData['childPrice']    = $value['childCostPrice'];
									$departureDateData['seat']          = $value['stockNow'];
									M3('product_departure_date_new')->add($departureDateData);
									
									$Log->webproductOperation($productID,M3('product_departure_date_new')->getLastSql());
								}
							}
							break;

						case '1':
							$library_time = M2('library_time')->where(array('libraryID'=>$library['id'],'departureTime'=>array('egt',time()),'stockNow'=>array('gt','0')))->select();
							foreach ($library_time as $key => $value)
							{
								if($value['adultCostPrice'] != false)
								{
									$departureDateData['productID']     = $productID;//................产品ID
									$departureDateData['libraryID']     = $library['id'];//................libraryID
									$departureDateData['departureID']   = $library['departureCity'];
									$departureDateData['departureTime'] = $value['departureTime'];
									$departureDateData['adultPrice']    = $value['adultCostPrice']+$addPriceNumsArr[$i];
									$departureDateData['childPrice']    = $value['childCostPrice']+$addPriceNumsArr[$i];
									$departureDateData['seat']          = $value['stockNow'];
									M3('product_departure_date_new')->add($departureDateData);
									
									$Log->webproductOperation($productID,M3('product_departure_date_new')->getLastSql());
								}
							}
							break;
						case '2':
							$library_time = M2('library_time')->where(array('libraryID'=>$library['id'],'departureTime'=>array('egt',time()),'stockNow'=>array('gt','0')))->select();
							foreach ($library_time as $key => $value)
							{
								if($value['adultCostPrice'] != false)
								{
									$departureDateData['productID']     = $productID;//................产品ID
									$departureDateData['libraryID']     = $library['id'];//................libraryID
									$departureDateData['departureID']   = $library['departureCity'];
									$departureDateData['departureTime'] = $value['departureTime'];
									$departureDateData['adultPrice']    = $value['adultCostPrice']+$value['adultCostPrice']*$addPriceNumsArr[$i]*0.01;
									$departureDateData['childPrice']    = $value['childCostPrice']+$value['adultCostPrice']*$addPriceNumsArr[$i]*0.01;
									$departureDateData['seat']          = $value['stockNow'];

									M3('product_departure_date_new')->add($departureDateData);
									
									$Log->webproductOperation($productID,M3('product_departure_date_new')->getLastSql());
								}
							}
							break;
					}


				}

				$areaIDArrCount   = count($areaIDArr);
				for ($i = 0; $i < $areaIDArrCount; $i++)
				{
					$destinationData['productID'] = $productID;
					$destinationData['areaID']    = $areaIDArr[$i];
					$destinationData['countryID'] = $countryIDArr[$i];
					$destinationData['cityID']    = $cityIDArr[$i];

					M3('product_destination_new')->add($destinationData);
					
					$Log->webproductOperation($productID,M3('product_destination_new')->getLastSql());
				}

				$labelIDCount = count($labelIDArr);
				for ($i=0; $i < $labelIDCount; $i++)
				{
					$labelData['productID'] = $productID;
					$labelData['labelID']   = $labelIDArr[$i];
					M3('product_label_new')->add($labelData);
					
					$Log->webproductOperation($productID,M3('product_label_new')->getLastSql());
				}

				$categoryLabelCount = count($categoryLabelArr);
				for ($i=0; $i < $categoryLabelCount; $i++)
				{
					$categoryData['productID']        = $productID;
					$categoryData['categoryParentID'] = $categoryID;
					$categoryData['categoryChildID']  = $packCategoryTwo;
					$categoryData['categoryLabelID']  = $categoryLabelArr[$i];
					M3('product_class_new')->add($categoryData);
					
					$Log->webproductOperation($productID,M3('product_class_new')->getLastSql());
				}

				$libraryCurr = M2('library')->field('id,productID,costInclude,costNotInclude,subscribeNotice,unSubscribeNotice')->where(array('productID'=>$libraryIDArr['0']))->find();

				//产品详情
				$detailData['productID']           = $productID;
				$detailData['costInclude']         = $libraryCurr['costInclude'];
				$detailData['costNoclude']         = $libraryCurr['costNotInclude'];
				$detailData['reservationNotice']   = $libraryCurr['subscribeNotice'];
				$detailData['unreservationNotice'] = $libraryCurr['unSubscribeNotice'];
				M3('product_detail_new')->add($detailData);
				
				$Log->webproductOperation($productID,M3('product_detail_new')->getLastSql());

				$libraryTimeID = M2('library_time')->where(array('libraryID'=>$libraryCurr['id'],'departureTime'=>array('gt',time()),'stockNow'=>array('gt','0')))->order('departureTime ASC')->getField('id');

				//酒店
				$library_time_hotel = M2('library_time_hotel')->field('hotelName,hotelStar,hotelAddress,hotelUrl,hotelSingle,hotelUpdate')->where(array('libraryID'=>$libraryCurr['id'],'libraryTimeID'=>$libraryTimeID))->find();
				if(empty($library_time_hotel) == false)
				{

					$hotelManageData['productID']   = $productID;
					$hotelManageData['spreadHotel'] = $library_time_hotel['hotelSingle'];
					$hotelManageData['updateHotel'] = $library_time_hotel['hotelUpdate'];
					$hotelManageData['hotelName']   = $library_time_hotel['hotelName'];
					$hotelManageData['dateLine']    = time();
					$hotelManageData['updateTime']  = time();
					$hotelManageData['sort']        = 1;
					$hotelManageData['status']      = 1;

					M3('product_hotelinfo_new')->add($hotelManageData);
					
					$Log->webproductOperation($productID,M3('product_hotelinfo_new')->getLastSql());
				}

				//航班
				$library_time_flight = M2('library_time_flight')->field('flightType,flightDay,airlineName,flightNumber,departureTime,arrivalTime')->where(array('libraryID'=>$libraryCurr['id'],'libraryTimeID'=>$libraryTimeID))->select();
				if(empty($library_time_flight) == false)
				{
					$flightData['productID'] = $productID;
					$flightData['title']     = '航班参考一';
					$flightData['sort']      = '1';

					$flightID = M3('product_routeinfo_new')->add($flightData);
					
					$Log->webproductOperation($productID,M3('product_routeinfo_new')->getLastSql());
					foreach ($library_time_flight as $key => $value)
					{

						$airplaneData['airlineID']            = $flightID;
						$airplaneData['productID']            = $productID;
						$airplaneData['title']                = '第'.$value['flightDay'].'天';
						$airplaneData['departureTime']        = $value['departureTime'];
						$airplaneData['type']                 = $value['flightType'];
						$airplaneData['departurePlace']       = M2('departure')->where(array('id'=>$libraryCurr['departureCity']))->getField('name');
						$airplaneData['destinationPlace']     = M2('destination')->where(array('id'=>$libraryCurr['destinationCity']))->getField('name');
						$airplaneData['destinationTime']      = $value['arrivalTime'];
						$airplaneData['flightName']           = $value['airlineName'];
						$airplaneData['flightNumber']         = trim($value['flightNumber']);
						$airplaneData['sort']                 = $key+1;
						$airplaneData['status']               = 1;

						M3('product_airlineinfo_new')->add($airplaneData);
						
						$Log->webproductOperation($productID,M3('product_airlineinfo_new')->getLastSql());
					}
				}

				$this->success('添加产品成功！',U(MODULE_NAME. '/Webproduct/sell'));
				exit();

			}
			else
			{
				$this->error('网络可能出问题了........');
				exit();
			}

		}
		//产品标签
		$this->productLabelHtml = productLabelHtml();
		$labelArr = M2('label_class')->where(array('pid'=>array('neq','0')))->select();
		$this->labelArr = $labelArr;


		//主站分类
		//分类标签
		$categoryArr       = M2('pack_product_classlabel')->where(array('pId'=>'0'))->select();
		$this->categoryArr = $categoryArr;

		//出发地
		$this->departureHtml = departureHtml('','departureCityID[]');

		//目的地
		$destinationHtml                  = array();
		$destinationHtml['areaSelect']    = destinationHtml('', 'areaID[]', '1', 'destinationSelect(this)');
		$destinationHtml['countrySelect'] = destinationHtml('', 'countryID[]', '2', 'destinationSelect(this)');
		$destinationHtml['citySelect']    = destinationHtml('', 'cityID[]', '3');
		$this->destinationHtml            = $destinationHtml;

		$this->menuID   = '152';
		$this->menuName = '自由行产品添加';
		$this->display();
    }

    /**
     * [selledit description]
     * @return [type] [description]
     */
	public function selledit()
	{

		$id         = I('get.id');
		$this->id   = $id;
		$step       = I('get.step',0);
		$this->step = $step;

		if(IS_POST)
		{
			//引入日志类
			$Log       = new \Model\Log();
			switch ($step)
			{
				case '0':
					$data['title']                = I('post.title');
					$data['verify']               = I('post.verify',1);
					$data['extend']               = I('post.extend');
					$data['special']              = I('post.special',0);
					$data['description']          = I('post.description');
					$data['keyWords']             = I('post.keyWords');
					
					//产品标签
					$labelIDArr                   = I('post.labelID',array());
					
					//主站分类标签
					$categoryID                   = I('post.categoryID');
					$packCategoryTwo              = I('post.packCategoryTwo');
					$categoryLabelArr             = I('post.categorylabel',array());
					
					//进销存产品绑定
					$libraryIDArr                 = I('post.libraryID',array());
					$addPriceTypeArr              = I('post.addPriceType',array());
					$addPriceNumsArr              = I('post.addPriceNums',array());
					
					//目的地
					$areaIDArr                    = I('post.areaID',array());
					$countryIDArr                 = I('post.countryID',array());
					$cityIDArr                    = I('post.cityID',array());
					
					$data['travelDays']           = I('post.travelDays');
					$data['travelNight']          = I('post.travelNight');
					$data['marketPrice']          = I('post.marketPrice');
					$data['sellPrice']            = I('post.price');
					
					$data['thumbImages']          = I('post.thumbImages');
					$originalImages               = I('post.originalImages');
					$data['originalImagesPC']     = $originalImages;
					$pathArr                      = explode('/',$originalImages);
					$imgname                      = end($pathArr);
					
					$originalImagesMobile = str_replace($imgname,'mobile_'.$imgname,$originalImages);

					if( !@fopen( $originalImagesMobile , 'r' ) )
				    {
				    	$arr = explode('.',$imgname);

				        $dataPost = array(
		            		'ext'=>$arr[1],
		            		'saveName'=>$imgname,
		            		'savePath'=>str_replace('http://www.tripvip.cn/Upload/','',str_replace($imgname,'',$originalImages)),
		            		'randNums'=>substr($arr[0],0,6)
		        		);

		            	$ch = curl_init ();
						curl_setopt ( $ch, CURLOPT_URL, 'http://www.tripvip.cn/center/public/cropBigPic' );
						curl_setopt ( $ch, CURLOPT_POST, 1 );
						curl_setopt ( $ch, CURLOPT_HEADER, 0 );
						curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
						curl_setopt ( $ch, CURLOPT_POSTFIELDS, $dataPost );
						$mobileUrl = curl_exec ( $ch );
						curl_close ( $ch );
				    }
				    $data['originalImagesMobile'] = 'http://www.tripvip.cn'.$mobileUrl;
					$data['class']                = '1';
					$data['createTime']           = time();
					$data['adduserID']            = getIdenty();

					$result = M3('product_new')->where(array('id'=>$id))->save($data);

					$Log->webproductOperation($id,M3('product_new')->getLastSql());

					M3('product_library_new')->where(array('productID'=>$id))->delete();
					M3('product_departure_date_new')->where(array('productID'=>$id))->delete();

					$libraryIDCount = count($libraryIDArr);
					for ($i=0; $i < $libraryIDCount; $i++)
					{

						$product_line_libraryData['productID']    = $id;

						$library = M2('library')->field('id,productID,name,class,destinationContinent,destinationCountry,destinationCity,departureCity')->where(array('productID'=>$libraryIDArr[$i]))->find();
						$product_line_libraryData['libraryID']        = $library['id'];
						$product_line_libraryData['libraryTitle']     = $library['name'];
						$product_line_libraryData['libraryProductID'] = $library['productID'];
						$product_line_libraryData['departureID']      = $library['departureCity'];

						$product_line_libraryData['areaID']           = $library['destinationContinent'];
						$product_line_libraryData['countryID']        = $library['destinationCountry'];
						$product_line_libraryData['cityID']           = $library['destinationCity'];
						$product_line_libraryData['gainType']         = $addPriceTypeArr[$i];

						switch ($addPriceTypeArr[$i])
						{
							case '0':
								$product_line_libraryData['gainNums'] = 0;
								break;

							default:
								$product_line_libraryData['gainNums']  = $addPriceNumsArr[$i];
								break;
						}

						M3('product_library_new')->add($product_line_libraryData);

						$Log->webproductOperation($id,M3('product_library_new')->getLastSql());
						switch ($addPriceTypeArr[$i])
						{
							case '0':
								$library_time = M2('library_time')->where(array('libraryID'=>$library['id'],'departureTime'=>array('egt',time()),'stockNow'=>array('gt','0')))->select();
								foreach ($library_time as $key => $value)
								{
									if($value['adultCostPrice'] != false)
									{
										$departureDateData['productID']     = $id;//................产品ID
										$departureDateData['libraryID']     = $library['id'];//................libraryID
										$departureDateData['departureID']   = $library['departureCity'];
										$departureDateData['departureTime'] = $value['departureTime'];
										$departureDateData['adultPrice']    = $value['adultCostPrice'];
										$departureDateData['childPrice']    = $value['childCostPrice'];
										$departureDateData['seat']          = $value['stockNow'];
										M3('product_departure_date_new')->add($departureDateData);

										$Log->webproductOperation($id,M3('product_departure_date_new')->getLastSql());
									}
								}
								break;

							case '1':
								$library_time = M2('library_time')->where(array('libraryID'=>$library['id'],'departureTime'=>array('egt',time()),'stockNow'=>array('gt','0')))->select();
								foreach ($library_time as $key => $value)
								{
									if($value['adultCostPrice'] != false)
									{
										$departureDateData['productID']     = $id;//................产品ID
										$departureDateData['libraryID']     = $library['id'];//................libraryID
										$departureDateData['departureID']   = $library['departureCity'];
										$departureDateData['departureTime'] = $value['departureTime'];
										$departureDateData['adultPrice']    = $value['adultCostPrice']+$addPriceNumsArr[$i];
										$departureDateData['childPrice']    = $value['childCostPrice']+$addPriceNumsArr[$i];
										$departureDateData['seat']          = $value['stockNow'];
										M3('product_departure_date_new')->add($departureDateData);

										$Log->webproductOperation($id,M3('product_departure_date_new')->getLastSql());
									}
								}
								break;
							case '2':
								$library_time = M2('library_time')->where(array('libraryID'=>$libraryIDArr[$i],'departureTime'=>array('egt',time()),'stockNow'=>array('gt','0')))->select();
								foreach ($library_time as $key => $value)
								{
									if($value['adultCostPrice'] != false)
									{
										$departureDateData['productID']     = $id;//................产品ID
										$departureDateData['libraryID']     = $library['id'];//................libraryID
										$departureDateData['departureID']   = $library['departureCity'];
										$departureDateData['departureTime'] = $value['departureTime'];
										$departureDateData['adultPrice']    = $value['adultCostPrice']*$addPriceNumsArr[$i];
										$departureDateData['childPrice']    = $value['childCostPrice']*$addPriceNumsArr[$i];
										$departureDateData['seat']          = $value['stockNow'];
										M3('product_departure_date_new')->add($departureDateData);

										$Log->webproductOperation($id,M3('product_departure_date_new')->getLastSql());
									}
								}
								break;
						}

					}

					//目的地
					M3('product_destination_new')->where(array('productID'=>$id))->delete();
					$areaIDArrCount   = count($areaIDArr);
					for ($i = 0; $i < $areaIDArrCount; $i++)
					{
						$destinationData['productID'] = $id;
						$destinationData['areaID']    = $areaIDArr[$i];
						$destinationData['countryID'] = $countryIDArr[$i];
						$destinationData['cityID']    = $cityIDArr[$i];

						M3('product_destination_new')->add($destinationData);

						$Log->webproductOperation($id,M3('product_destination_new')->getLastSql());
					}

					//标签
					M3('product_class_new')->where(array('productID'=>$id))->delete();
					$labelIDCount   = count($labelIDArr);

					for ($i=0; $i < $labelIDCount; $i++)
					{
						$labelData['productID'] = $id;
						$labelData['labelID']   = $labelIDArr[$i];

						M3('product_label_new')->add($labelData);

						$Log->webproductOperation($id,M3('product_label_new')->getLastSql());
					}

					//分类
					M3('product_label_new')->where(array('productID'=>$id))->delete();
					$categoryLabelCount     = count($categoryLabelArr);

					for ($i=0; $i < $categoryLabelCount; $i++)
					{
						$categoryData['productID']        = $id;
						$categoryData['categoryParentID'] = $categoryID;
						$categoryData['categoryChildID']  = $packCategoryTwo;
						$categoryData['categoryLabelID']  = $categoryLabelArr[$i];
						M3('product_class_new')->add($categoryData);

						$Log->webproductOperation($id,M3('product_class_new')->getLastSql());
					}

					break;
				case '1':
					M3('product_highlight_new')->where(array('productID'=>$id))->delete();

					$content = I('post.content',array());
					$reson   = I('post.reson',array());
					$sort    = I('post.sort',array());
					$count   = count($content);
					for ($i=0; $i < $count; $i++)
					{
						$data['productID'] = $id;
						$data['content']   = $content[$i];
						$data['reson']     = $reson[$i];
						$data['sort']      = $sort[$i];
						$result = M3('product_highlight_new')->add($data);

						$Log->webproductOperation($id,M3('product_highlight_new')->getLastSql());

					}
					break;
				case '2':
					$data['costInclude']         = I('post.costInclude', '');
					$data['costNoclude']         = I('post.costNoclude', '');
					$data['reservationNotice']   = I('post.reservationNotice', '');
					$data['unreservationNotice'] = I('post.unreservationNotice', '');

					$detailRow = M2('product_detail_new')->where(array('productID'=>$id))->find();
					if($detailRow)
					{
						$result = M3('product_detail_new')->where(array('productID'=>$id))->save($data);
					}
					else
					{
						$data['productID'] = $id;
						$result = M3('product_detail_new')->add($data);
					}
					$Log->webproductOperation($id,M3('product_detail_new')->getLastSql());
					break;
				case '9':
					$data['recommend']              = I('post.recommend');
					$data['headerImg']              = I('post.headerImg');
					$data['reson']                  = I('post.reson');
					$data['recommendHotleReson']    = I('post.recommendHotleReson');
					$data['recommendAirplaneReson'] = I('post.recommendAirplaneReson');
					$find = M2('product_recommendinfo_new')->where(array('productID'=>$id))->find();
					if($find == false)
					{
						$data['productID'] = $id;
						$result = M3('product_recommendinfo_new')->add($data);
					}
					else
					{
						$result = M3('product_recommendinfo_new')->where(array('productID'=>$id))->save($data);
					}
					$Log->webproductOperation($id,M3('product_recommendinfo_new')->getLastSql());
					break;

			}

			if($result !== false)
			{
				$this->success('修改产品成功！');
			}
			else
			{
				$this->error('修改产品失败！');
			}
			exit;
		}


		//产品基本信息
		$product       = M2('product_new')->where(array('id'=>$id,'class'=>'1'))->find();
		$this->product = $product;

		switch ($step)
		{
			case '0':
				//产品标签
				$this->productLabelHtml = productLabelHtml();

				$productLabel = M2('product_label_new')->where(array('productID'=>$product['id']))->select();
				$currLabelArr = array();
				foreach ($productLabel as $key => $value)
				{
					$currLabelArr[$key] = $value['labelID'];
				}

				$labelArr = M2('label_class')->where(array('pid'=>array('neq','0')))->select();
				foreach ($labelArr as $key => $value)
				{
					if(in_array($value['id'],$currLabelArr))
					{
						$labelArr[$key]['checked'] = 'checked';
					}
				}
				$this->labelArr = $labelArr;

				//主站分类
				//分类标签

				$LabelClassArr   = M2('product_class_new')->where(array('productID'=>$product['id']))->select();
				$currLabelClassArr = array();
				foreach ($LabelClassArr as $key => $value)
				{
					$currLabelClassArr['categoryParentID']      = $value['categoryParentID'];
					$currLabelClassArr['categoryChildID']       = $value['categoryChildID'];
					$currLabelClassArr['categoryLabelID'][$key] = $value['categoryLabelID'];
				}

				//
				$classParentArr  = M2('pack_product_classlabel')->where(array('pId'=>'0'))->select();
				$classParentOption = '';
				foreach ($classParentArr as $key => $value)
				{
					if($value['id'] == $currLabelClassArr['categoryParentID'])
					{
						$classParentOption .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
					}
					else
					{
						$classParentOption .= '<option value="'.$value['id'].'" >'.$value['name'].'</option>';
					}
				}
				$this->classParentOption = $classParentOption;

				$classChlidArr = M2('pack_product_classlabel')->where(array('pId'=>$currLabelClassArr['categoryParentID']))->select();
				$classChlidOption = '';
				foreach ($classChlidArr as $key => $value)
				{
					if($value['id'] == $currLabelClassArr['categoryChildID'])
					{
						$classChlidOption .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
					}
					else
					{
						$classChlidOption .= '<option value="'.$value['id'].'" >'.$value['name'].'</option>';
					}
				}

				$this->classChlidOption = $classChlidOption;


				//主站分类标签
				$classLabelArr = M2('pack_product_classlabel')->where(array('pId'=>$currLabelClassArr['categoryChildID']))->select();
				foreach ($classLabelArr as $key => $value)
				{
					if(in_array($value['id'],$currLabelClassArr['categoryLabelID']))
					{
						$classLabelArr[$key]['checked'] = 'checked';
					}
				}
				$this->classLabelArr = $classLabelArr;

				$productLineLibraryInfo = M2('product_library_new')->where(array('productID'=>$product['id']))->select();

				//出发地
				$currDepartureArr = array();
				if($productLineLibraryInfo)
				{

					foreach ($productLineLibraryInfo as $key => $value)
					{
						//出发地
						$currDepartureArr[$key]['libraryID']     = $value['libraryID'];
						$currDepartureArr[$key]['departureName'] = M2('departure')->where(array('id'=>$value['departureID']))->getField('name');
						$currDepartureArr[$key]['libraryTitle']  = $value['libraryTitle'];
						$currDepartureArr[$key]['gainType']      = $value['gainType'];
						$currDepartureArr[$key]['gainNums']      = $value['gainNums'];
						$costPrice = M2('library_time')->where(array('libraryID'=>$value['libraryID'],'departureTime'=>array('gt',time())))->order('departureTime ASC')->getField('adultCostPrice');

						switch ($value['gainType'])
						{
							case '0':
								$sellPrice = ceil($costPrice);
								break;
							case '1':
								$sellPrice = ceil($costPrice + $value['gainNums']);
								break;
							case '2':
								$sellPrice = ceil($costPrice + $costPrice*$value['gainNums']*0.01);
								break;
						}
						$currDepartureArr[$key]['sellPrice']        = $sellPrice;
						$currDepartureArr[$key]['costPrice']        = $costPrice;
						$currDepartureArr[$key]['libraryProductID'] = $value['libraryProductID'];
					}
				}

				$this->currDepartureArr = $currDepartureArr;

				//目的地
				$currDestinationArr = array();
				$destinationArr = M2('product_destination_new')->where(array('productID'=>$product['id']))->select();
				if($destinationArr)
				{

					foreach ($destinationArr as $key => $value)
					{
						//目的地
						$currDestinationArr[$key]['areaSelect']    = destinationHtml($value['areaID'], 'areaID[]', '1', 'destinationSelect(this)');
						$currDestinationArr[$key]['countrySelect'] = destinationHtml($value['countryID'], 'countryID[]', '2', 'destinationSelect(this)');
						$currDestinationArr[$key]['citySelect']    = destinationHtml($value['cityID'], 'cityID[]', '3');
					}
				}
				else
				{
					$currDestinationArr['0']['areaSelect']    = destinationHtml('', 'areaID[]', '1', 'destinationSelect(this)');
					$currDestinationArr['0']['countrySelect'] = destinationHtml('', 'countryID[]', '2', 'destinationSelect(this)');
					$currDestinationArr['0']['citySelect']    = destinationHtml('', 'cityID[]', '3');
				}
				$this->currDestinationArr = $currDestinationArr;

				//目的地
				$destinationHtml                  = array();
				$destinationHtml['areaSelect']    = destinationHtml('', 'areaID[]', '1', 'destinationSelect(this)');
				$destinationHtml['countrySelect'] = destinationHtml('', 'countryID[]', '2', 'destinationSelect(this)');
				$destinationHtml['citySelect']    = destinationHtml('', 'cityID[]', '3');
				$this->destinationHtml            = $destinationHtml;

				break;
			case '1':
				//产品亮点
				$highlight = M2('product_highlight_new')->where(array('productID'=>$product['id']))->order('sort')->select();
				$this->highlight = $highlight;

				break;
			case '2':
				//费用包含
				$detail = M2('product_detail_new')->where(array('productID'=>$product['id']))->find();
				$this->detail = $detail;

				break;
			case '5':
				//当地游
				$whereLocalProduct['type']      = 5;
				$whereLocalProduct['productID'] = $product['id'];
				$LocalProductArr                = M2('product_contains_new')->where($whereLocalProduct)->select();
				foreach($LocalProductArr as $key => $value)
				{
					$containsRow = M2('pack_product_travel')
									->join('tripvip.cms_pack_departure_date ON cms_pack_product_travel.id = cms_pack_departure_date.productID')
									->distinct('true')
									->field('title,adultPrice as costPrice,litPic AS uploadImg')
									->where(array('cms_pack_product_travel.id'=>$value['containID']))
									->order('adultPrice DESC')
									->find();

					if($containsRow !== false)
					{
						$LocalProductArr[$key]['title']     = $containsRow['title'];
						$LocalProductArr[$key]['costPrice'] = $containsRow['costPrice'];
						$LocalProductArr[$key]['uploadImg'] = $containsRow['uploadImg'];
					}
					else
					{
						unset($LocalProductArr[$key]);
					}
				}

				$this->LocalProductArr1 = $LocalProductArr;
				$this->LocalProductArr2 = $LocalProductArr;

				break;
			case '6':
				//附加保险
				$whereInsurance['type']      = 1;
				$whereInsurance['productID'] = $product['id'];
				$insuranceArr                = M2('product_contains_new')->where($whereInsurance)->select();
				foreach($insuranceArr as $key => $value)
				{
					$containsRow = M2('pack_contains')->where(array('id'=>$value['containID']))->find();
					if($containsRow !== false)
					{
						$insuranceArr[$key]['title']     = $containsRow['title'];
						$insuranceArr[$key]['costPrice'] = $containsRow['price'];
						$insuranceArr[$key]['uploadImg'] = $containsRow['uploadImg'];
					}
					else
					{
						unset($insuranceArr[$key]);
					}
				}
				$this->insuranceArr1 = $insuranceArr;
				$this->insuranceArr2 = $insuranceArr;
				break;
			case '7':
				//优惠券

				break;
			case '8':
				//附加产品
				$whereAddProduct['type']      = 2;
				$whereAddProduct['productID'] = $product['id'];
				$addProductArr               = M2('product_contains_new')->where($whereAddProduct)->select();
				foreach($addProductArr as $key => $value)
				{
					$containsRow = M2('pack_contains')->where(array('id'=>$value['containID']))->find();
					if($containsRow !== false)
					{
						$addProductArr[$key]['title']     = $containsRow['title'];
						$addProductArr[$key]['costPrice'] = $containsRow['price'];
						$addProductArr[$key]['uploadImg'] = $containsRow['uploadImg'];
					}
					else
					{
						unset($addProductArr[$key]);
					}
				}
				$this->addProductArr1 = $addProductArr;
				$this->addProductArr2 = $addProductArr;
				break;
			case '9':
				//棉签妹推荐
				$this->personRecommend = M2('product_recommendinfo_new')->where(array('productID'=>$product['id']))->find();
				break;
			case '10':
				//包含单品
				$whereSingle['type']      = 3;
				$whereSingle['productID'] = $product['id'];
				$productSingleArr         = M2('product_contains_new')->where($whereSingle)->select();
				foreach($productSingleArr as $key => $value)
				{
					$containsRow = M2('pack_contains')->where(array('id'=>$value['containID']))->find();
					if($containsRow !== false)
					{
						$productSingleArr[$key]['title']     = $containsRow['title'];
						$productSingleArr[$key]['costPrice'] = $containsRow['price'];
						$productSingleArr[$key]['uploadImg'] = $containsRow['uploadImg'];
					}
					else
					{
						unset($productSingleArr[$key]);
					}
				}
				$this->productSingleArr1 = $productSingleArr;
				$this->productSingleArr2 = $productSingleArr;

				break;
			case '11':
				//赠送单品
				$whereGifts['type']      = 4;
				$whereGifts['productID'] = $product['id'];
				$giftsArr                = M2('product_contains_new')->where($whereGifts)->select();
				foreach($giftsArr as $key => $value)
				{
					$containsRow = M2('pack_contains')->where(array('id'=>$value['containID']))->find();
					if($containsRow !== false)
					{
						$giftsArr[$key]['title']     = $containsRow['title'];
						$giftsArr[$key]['costPrice'] = $containsRow['price'];
						$giftsArr[$key]['uploadImg'] = $containsRow['uploadImg'];
					}
					else
					{
						unset($giftsArr[$key]);
					}
				}
				$this->giftsArr1 = $giftsArr;
				$this->giftsArr2 = $giftsArr;
				break;
			case '12':
				//出行日期
				$departureArr = M2('product_library_new')->field('libraryID,departureID')->where(array('productID'=>$product['id']))->select();
				foreach ($departureArr as $key => $value)
				{
					$departureArr[$key]['departureName'] = M2('departure')->where(array('id'=>$value['departureID']))->getField('name');
				}
				$this->departureArr = $departureArr;
				// $departureDateArr = M2('pack_departure_date')->where(array('productID'=>$product['id']))->select();
				$libraryID                       = I('get.libraryID',0);
				$this->libraryID                 = $libraryID;
				$whereDepartureDate['productID'] = $product['id'];
				if($libraryID != false)$whereDepartureDate['libraryID'] = $libraryID;
				$count                           = M2('product_departure_date_new')->where($whereDepartureDate)->count();
				$PageClass                       = new \Think\Page($count,15);
				$page                            = $PageClass->show();

				$departureDateArr = M2('product_departure_date_new')->where($whereDepartureDate)->limit($PageClass->firstRow.','.$PageClass->listRows)->select();

				$this->page       = $page;
				$this->departureDateArr = $departureDateArr;

				break;
			case '13':
				//航班信息

				$whereAirLine['productID'] = $product['id'];
				$airLineArr                = M2('product_routeinfo_new')->where($whereAirLine)->limit($PageClass->firstRow.','.$PageClass->listRows)->order('sort')->select();
				foreach ($airLineArr as $key => $value)
				{
					$airLineArr[$key]['airLineInfo'] = M2('product_airlineinfo_new')->where(array('airlineID'=>$value['id'],'status'=>'1'))->order('sort')->select();
				}
				$this->airLineArr          = $airLineArr;
				break;
			case '14':
				//酒店信息

				$whereHotel['productID'] = $product['id'];
				$count                   = M2('product_hotelinfo_new')->where($whereHotel)->count();
				$PageClass               = new \Think\Page($count,15);
				$page                    = $PageClass->show();

				$hotelArr                = M2('product_hotelinfo_new')->where($whereHotel)->limit($PageClass->firstRow.','.$PageClass->listRows)->order('sort')->select();
				foreach ($hotelArr as $key => $value)
				{
					$hotel = M2('hotel')->field('name,ename,address,litpic')->where(array('id'=>$value['hotelID']))->find();
					$hotelArr[$key]['name']    = $hotel['name'];
					$hotelArr[$key]['ename']   = $hotel['ename'];
					$hotelArr[$key]['address'] = $hotel['address'];
					$hotelArr[$key]['litpic']  = $hotel['litpic'];
				}
				$this->page              = $page;
				$this->hotelArr          = $hotelArr;
				break;
			case '15':
				//参考行程

				$whereTravelreference['productID'] = $product['id'];
				$count                    = M2('product_travelinfo_new')->where($whereTravelreference)->count();
				$PageClass                = new \Think\Page($count,15);
				$page                     = $PageClass->show();

				$travelreferenceArr       = M2('product_travelinfo_new')->where($whereTravelreference)->limit($PageClass->firstRow.','.$PageClass->listRows)->order('sort')->select();
				$this->page               = $page;
				$this->travelreferenceArr = $travelreferenceArr;
				break;
		}

		/*$codesStrArr = M2('coupons_cooperation')->where(array('cp_code'=>array(array('neq',''),array('neq','0'))))->getField('cp_code',true);
		$codesStr    =  implode(',',$codesStrArr);
		echo $codesStr;*/

		$this->website_url = C('website_url');
		$this->menuID      = '152';
		$this->menuName    = '自由行产品编辑';
		$this->display();
	}

    /**
     * [getClassLabel description]
     * @return [type] [description]
     */
    public function getClassLabel()
    {
		$id       = I('post.id',0);
		$keyWords = I('post.keyWords');
		$currID   = I('post.currID',array());
		$where    = array();
		if($id == false)
		{
			$where['pid']  = array('neq','0');
		}
		else
		{
			$where['pid']  = $id;
		}

		$where['name'] = array('LIKE',"%$keyWords%");

		$classLabelArr = M2('label_class')->where($where)->select();
		$labelArrHtml = '';

		foreach ($classLabelArr as $key => $value)
		{
			if(in_array($value['id'],$currID))
			{

    			$labelArrHtml .= '<li style="position: relative;display: block; min-width: 60px; height: 24px;">';
                	$labelArrHtml .= '<input type="checkbox" name="label[]" value="'.$value['id'].'" style="position: absolute; min-width: 60px; height: 24px;  margin-right: 20px; opacity: 0; z-index: 99999;"onclick="currProductLabel(this,\''.$value['id'].'\',\''.$value['name'].'\')" checked="checked">';
                	$labelArrHtml .= '<span style="position: absolute; display: block; text-align: center; min-width: 60px; height: 24px;  top:0px; right: 0px; bottom: 0px; left: 0px; margin: auto; cursor: pointer; background-color: #59bc5e; color: #FFF; line-height: 24px; z-index: 1; ">'.$value['name'].'</span>';
              	$labelArrHtml .= '</li>';
			}
			else
			{
				$labelArrHtml .= '<li style="position: relative;display: block; min-width: 60px; height: 24px;">';
                	$labelArrHtml .= '<input type="checkbox" name="label[]" value="'.$value['id'].'" style="position: absolute; min-width: 60px; height: 24px;  margin-right: 20px; opacity: 0; z-index: 99999;"onclick="currProductLabel(this,\''.$value['id'].'\',\''.$value['name'].'\')">';
                	$labelArrHtml .= '<span style="position: absolute; display: block; text-align: center; min-width: 60px; height: 24px;  top:0px; right: 0px; bottom: 0px; left: 0px; margin: auto; cursor: pointer; background-color: #CCC; color: #FFF; line-height: 24px; z-index: 1; ">'.$value['name'].'</span>';
              	$labelArrHtml .= '</li>';
			}
		}

    	$data['valid'] = true;
		$data['data'] = $labelArrHtml;

    	$this->ajaxReturn($data);
    }
    /**
     * [checkDeparture description]
     * @return [type] [description]
     */
    public function checkDepartureAjax()
    {
    	$productID = I('post.productID');
    	$result = M2('pack_departuredate')->where(array('pid'=>$productID,'departuretime'=>array('gt',time()),'seat'=>array('gt','0')))->find();
    	if($result == false)
    	{
    		$data['valid'] = false;
    		$data['state'] = '请添加出团时间';
    	}
    	else
    	{
    		$data['valid'] = true;
    	}
    	$this->ajaxReturn($data);
    }

    /**
     * [getLibraryAjax description]
     * @return [type] [description]
     */
    public function getLibraryAjax()
    {
		$data      = array('valid'=>false);
		$libraryID = I('post.libraryID');
		$result    = M2('library')->where(array('productID'=>$libraryID))->find();
    	if($result != false)
    	{
			$data['departureName'] = M2('departure')->where(array('id'=>$result['departureCity']))->getField('name');
			$data['libraryTitle']  = $result['name'];
			$data['price']         = M2('library_time')->where(array('libraryID'=>$result['id'],'departureTime'=>array('gt',time()),'stockNow'=>array('gt','0')))->order('departureTime ASC')->getField('adultCostPrice');
			if($data['price'] != false)$data['valid'] = true;

    	}
    	else
    	{
    		$data['valid'] = false;
    	}

    	$this->ajaxReturn($data);
    }
    /**
     * 直销产品分类
     * @return [type] [description]
     */
    public function sellcategory()
    {
    	$list = M3('pack_product_classlabel')->where(array('pId'=>'0'))->order('sort')->select();

    	foreach ($list as $key => $value)
    	{
    		$list[$key]['class'] = M3('pack_product_classlabel')->where(array('pId'=>$value['id']))->order('sort')->select();

    		foreach ($list[$key]['class'] as $k => $v)
    		{
    			$list[$key]['class'][$k]['label'] = M2('pack_product_classlabel')->where(array('pId'=>$v['id']))->select();
    		}
    	}

    	$this->list = $list;
    	$this->menuID   = '77';
		$this->menuName = '直销产品分类';
    	$this->display();
    }

	/**
	 * [productTypeAjax description]
	 * @return [type] [description]
	 */
	public function productTypeAjax()
	{
		$return = array('valid' => false ,'state' => '操作失败');
		$type          = I('post.type');
		switch ($type)
		{
			case '5':
				$where['type']   = '2';
				$where['status'] = '1';
				$where['departureTime'] = array('gt',time());
				$list = M2('product_new')
						->join('tripvip.cms_product_departure_date_new ON cms_product_new.id = cms_product_departure_date_new.productID')
						->distinct('true')
						->field('cms_product_new.id,title,adultPrice as price,litPic AS uploadImg')
						->where($where)
						->order('adultPrice DESC')
						->select();
				break;
			default:
			case '6':
				$where['endExchangeTime'] = array('gt',time()-24*60*60);
				$list = M2('pack_coupons')->where($where)->select();
				foreach ($list as $key => $value)
				{
					switch ($value['codeType'])
					{
						case '1':
							$list[$key]['title'] = $value['name'].'-'.$value['price'].'折';
							$list[$key]['price'] = $value['price'].'元';
							break;
						case '2':
							$list[$key]['title'] = $value['name'].'-'.$value['price'].'折';
							$list[$key]['price'] = $value['price'].'折';
							break;
					}

					$list[$key]['uploadImg'] = '/Public/Center/images/baoxian.jpg';
				}
				break;
			default:
				$where['type'] = $type;
				$list = M2('pack_contains')->where($where)->order('id DESC')->select();
				break;
		}

		if($list != false)
		{
			$return = array('valid' => true ,'state' => '操作成功','info'=>$list);
		}
		else
		{
			$return['state'] = '没有此类产品要去添加吗？';
		}
		$this->ajaxReturn($return);
	}

	public function getProductType()
	{

		$return = array('valid' => false ,'state' => '操作失败');
		if(IS_POST)
		{
			$id                 = I('post.id');
			$data['type']       = I('post.type');
			$data['productID']  = I('post.productID');
			$data['containID']  = I('post.containID');
			$data['upPrice']    = I('post.upPrice');
			$data['buyType']    = I('post.buyType');
			switch ($data['type'])
			{
				case '5':
					$price = M2('product_departure_date_new')->where(array('productID'=>$data['containID'],'departureTime'=>array('gt',time())))->order('adultPrice DESC')->getField('adultPrice');
					break;

				default:
					$price = M2('pack_contains')->where(array('id'=>$data['containID']))->getField('price');
					break;
			}
			$data['totalPrice'] = $price + $data['upPrice'];

			if($id)
			{
				$result = M3('product_contains_new')->where(array('id'=>$id))->save($data);
			}
			else
			{
				$containsRow = M2('product_contains_new')->where(array('containID'=>$data['containID'],'productID'=>$data['productID'],'type'=>$data['type']))->find();
				if($containsRow)
				{
					$return = array('valid' => false ,'state' => '请不要重复添加同一个产品');
				}
				else
				{
					$result = M3('product_contains_new')->add($data);
				}

			}
			if($result != false)
			{
				$return = array('valid' => true ,'state' => '操作成功');
			}
		}
		$this->ajaxReturn($return);
	}

	public function getProductTypeDel()
	{
		$return = array('valid' => false ,'state' => '操作失败');

		$id     = I('post.id');
		$result = M3('product_contains_new')->where(array('id'=>$id))->delete();

		if($result != false)
		{
			$return = array('valid' => true ,'state' => '删除成功');
		}

		$this->ajaxReturn($return);
	}
	/**
	 * [departureDate description]
	 * @return [type] [description]
	 */
	public function departureDate()
	{
		layout(false);

		$productID = I('get.productID');
		$this->productID = $productID;
		$this->productTitle = M2('product_new')->where(array('id'=>$productID))->getField('title');
		if(IS_POST)
		{
			$data['departureID'] = I('post.departureID');
			$data['adultPrice']  = I('post.adultPrice');
			$data['childPrice']  = I('post.childPrice');
			$data['seat']        = I('post.seat');
			$alonetime           = I('post.timelist2');

			$time               = explode('|0,', $alonetime);
			$time               = array_filter($time);

			if(!empty($time))
			{
				$count = count($time);
				foreach ($time as $key => $value)
				{

					$time_array = explode('|',$value);
					$a          = strtotime($time_array[0]);
					$b          = strtotime($time_array[1]);
					$days       = ($b-$a)/86400;
					for ($i = 0; $i < $days; $i++)
					{

						$data['departureTime'] = $a+$i*86400;
						$departureDateRow = M2('departure_date_new')->where(array('productID'=>$productID,'departureID'=>$data['departureID'],'departureTime'=>$data['departureTime']))->find();
						if($departureDateRow)
						{
							M3('departure_date_new')->where(array('productID'=>$productID,'departureID'=>$data['departureID'],'departureTime'=>$data['departureTime']))->save($data);
						}
						else
						{
							$data['productID'] = $productID;
							M3('departure_date_new')->add($data);
						}
					}
				}
			}

			$this->success();
			exit;
		}
		$departureArr = M2('product_library_new')->field('libraryID,departureID')->where(array('productID'=>$productID))->select();
		foreach ($departureArr as $key => $value)
		{
			$departureArr[$key]['departureName'] = M2('departure')->where(array('id'=>$value['departureID']))->getField('name');
		}
		$this->departureArr = $departureArr;

		$this->display();
	}


	public function departureDatePost()
	{
		$return = array('valid' => false ,'state' => '操作失败');
		$productID = I('get.productID');
		if(IS_POST)
		{
			$data['libraryID']   = I('post.libraryID');
			$data['departureID'] = M2('product_library_new')->where(array('libraryID'=>$data['libraryID'],'productID'=>$productID))->getField('departureID');
			$data['adultPrice']  = I('post.adultPrice');
			$data['childPrice']  = I('post.childPrice');
			$data['seat']        = I('post.seat');
			$alonetime           = I('post.timelist2');

			$time               = explode('|0,', $alonetime);
			$time               = array_filter($time);

			if(!empty($time))
			{
				$count = count($time);
				foreach ($time as $key => $value)
				{

					$time_array = explode('|',$value);
					$a          = strtotime($time_array[0]);
					$b          = strtotime($time_array[1]);
					$days       = ($b-$a)/86400;
					for ($i = 0; $i < $days; $i++)
					{

						$data['departureTime'] = $a+$i*86400;
						$departureDateRow = M2('product_departure_date_new')->where(array('productID'=>$productID,'libraryID'=>$data['libraryID'],'departureTime'=>$data['departureTime']))->find();
						if($departureDateRow)
						{
							M3('product_departure_date_new')->where(array('productID'=>$productID,'libraryID'=>$data['libraryID'],'departureTime'=>$data['departureTime']))->save($data);
						}
						else
						{
							$data['productID'] = $productID;
							M3('product_departure_date_new')->add($data);
						}
					}
				}
			}

			$return = array('valid' => true ,'state' => '操作成功');

		}

		$this->ajaxReturn($return);
	}

	public function departureDateDel()
	{
		$id     = I('get.id');

		$result = M3('product_departure_date_new')->where(array('id'=>$id))->delete();
		if($result != false)
		{
			$this->success('删除出行日期成功');
		}
		else
		{
			$this->error('删除出行日期失败');
		}
		exit();
	}

	/**
	 * [hotelInfo description]
	 * @return [type] [description]
	 */
	public function hotelInfo()
	{
		layout(false);
		$id        = I('get.id');
		$this->id  = $id;
		$productID = I('get.productID');
		$this->productID = $productID;

		if($id != fasle)
		{
			$hotel = M2('product_hotelinfo_new')->where(array('id'=>$id))->find();
			$this->hotel = $hotel;
		}

		//产品信息
		$product       = M2('product_new')->field('id as productID,title as productTitle')->where(array('id'=>$productID))->find();
		$this->product = $product;

		//供应商列表
		$supplier       = M('supplier')->field('id,name')->where(array('status'=>2))->order('sort,id')->select();
		$this->supplier = $supplier;

		//目的地
		$productDestinationArr = M2('product_destination_new')->field('countryID')->where(array('productID'=>$product['productID']))->select();
		$currProductDestinationArr = array();
		foreach ($productDestinationArr as $key => $value)
		{
			$currProductDestinationArr[] = $value['countryID'];
		}

		//当前国家的酒店
		$destinationIDs = implode(',',$currProductDestinationArr);

		$hotelArr = M2('hotel')->field('id,country,city,name,litpic,address')->where(array('country'=>array('IN',$destinationIDs)))->order('id DESC')->select();

        foreach ($hotelArr as $key => $value)
        {
			$litpic                   = explode("!", $value['litpic']);
			$hotelArr[$key]['litpic'] = $litpic['0'];
        }

		$this->hotelArr = $hotelArr;
		$this->website_url = C('website_url');
		$this->display();
	}

	/**
	 * [hotelInfoPost description]
	 * @return [type] [description]
	 */
	public function hotelInfoPost()
	{
		$return    = array('valid' => false ,'state' => '操作失败');
		$id        = I('get.id');
		$productID = I('get.productID');
		if(IS_POST)
		{
			$hotelID             = I('post.hotelID');
			$data['productID']   = $productID;
			$data['supplierID']  = I('post.supplierID');
			$data['spreadHotel'] = I('post.spreadHotel');
			$data['updateHotel'] = I('post.updateHotel');
			$data['hotelID']     = $hotelID;
			$data['hotelName']   = M2('hotel')->where(array('id'=>$hotelID))->getField('name');
			$data['hotelTitle']  = I('post.hotelTitle');
			$data['updateTime']  = time();
			$data['sort']        = I('post.sort');
			$data['status']      = 1;

			if($id)
			{
				$result = M3('product_hotelinfo_new')->where(array('id'=>$id))->save($data);
			}
			else
			{
				$data['dateLine']     = time();
				$result = M3('product_hotelinfo_new')->add($data);
			}

			if($result != false)
			{
				$return = array('valid' => true ,'state' => '操作成功');
			}

		}
		$this->ajaxReturn($return);
	}

	/**
	 * [hotelInfoDel description]
	 * @return [type] [description]
	 */
	public function hotelInfoDel()
	{
		$id     = I('get.id');

		$result = M3('product_hotelinfo_new')->where(array('id'=>$id))->delete();

		if($result != false)
		{
			$this->success('删除酒店信息成功');
		}
		else
		{
			$this->error('删除酒店信息失败');
		}
		exit();
	}

	/**
	 * [travelreferenceInfo description]
	 * @return [type] [description]
	 */
	public function travelreferenceInfo()
	{
		layout(false);
		$id        = I('get.id');
		$this->id  = $id;
		$productID = I('get.productID');
		$this->productID = $productID;

		//产品信息
		$product       = M2('product_new')->field('id as productID,title as productTitle')->where(array('id'=>$productID))->find();
		$this->product = $product;

		if($id != fasle)
		{
			$travelreference       = M2('product_travelinfo_new')->where(array('id'=>$id))->find();
			$this->travelreference = $travelreference;
		}

		$this->website_url = C('website_url');
		$this->display();
	}

	/**
	 * [travelreferenceInfoPost description]
	 * @return [type] [description]
	 */
	public function travelreferenceInfoPost()
	{
		$return    = array('valid' => false ,'state' => '操作失败');
		$id        = I('get.id');
		$productID = I('get.productID');
		if(IS_POST)
		{
			$data['productID']    = $productID;
			$data['title']        = I('post.title');
			$data['content']      = I('post.content','','trim');
			$data['sort']         = I('post.sort',255);

			if($id)
			{
				$result = M3('product_travelinfo_new')->where(array('id'=>$id))->save($data);
			}
			else
			{
				$data['createTime']     = time();
				$result = M3('product_travelinfo_new')->add($data);
			}

			if($result != false)
			{
				$return = array('valid' => true ,'state' => '操作成功');
			}

		}
		$this->ajaxReturn($return);
	}

	/**
	 * [travelreferenceInfoDel description]
	 * @return [type] [description]
	 */
	public function travelreferenceInfoDel()
	{
		$id     = I('get.id');

		$result = M3('product_travelinfo_new')->where(array('id'=>$id))->delete();

		if($result != false)
		{
			$this->success('删除行程信息成功');
		}
		else
		{
			$this->error('删除行程信息失败');
		}
		exit();
	}

	/**
	 * [airpLineSetPost description]
	 * 航线编辑
	 * @return [type] [description]
	 */
	public function airpLineSetPost()
	{
		$return    = array('valid' => false ,'state' => '操作失败');
		$id        = I('get.id');
		$productID = I('get.productID');
		if(IS_POST)
		{
			$data['productID']    = $productID;
			$data['title']        = I('post.title');
			$data['description']  = I('post.description','','trim');
			$data['sort']         = I('post.sort',255);

			if($id)
			{
				$result = M3('product_routeinfo_new')->where(array('id'=>$id))->save($data);
			}
			else
			{
				$result = M3('product_routeinfo_new')->add($data);
			}

			if($result != false)
			{
				$return = array('valid' => true ,'state' => '操作成功');
			}

		}
		$this->ajaxReturn($return);
	}


	public function airpLineSet()
	{
		$return = array('valid' => false ,'state' => '操作失败');

		if(IS_POST)
		{
			$type   = I('post.type');
			$id     = I('post.id');

			switch ($type)
			{
				case 'airline':
					$info = M2('product_routeinfo_new')->where(array('id'=>$id))->find();
					break;
				case 'flight':
					$info = M2('product_airlineinfo_new')->where(array('id'=>$id))->find();
					break;
			}

			if($info)
			{
				$return = array('valid' => true ,'state' => '操作成功','info'=>$info);
			}

		}
		$this->ajaxReturn($return);
	}
	/**
	 * [airplaneInfo description]
	 * @return [type] [description]
	 */
	public function airplaneInfo()
	{
		layout(false);

		$id        = I('get.id');
		$this->id  = $id;
		$productID = I('get.productID');
		$this->productID = $productID;
		$airlineID = I('get.airlineID');
		$this->airlineID = $airlineID;

		//产品信息
		$product       = M2('product_new')->field('id as productID,title as productTitle')->where(array('id'=>$productID))->find();
		$this->product = $product;

		if($id != fasle)
		{
			$airlineInfo       = M2('product_airlineinfo_new')->where(array('id'=>$id))->find();
			$this->airlineInfo = $airlineInfo;
		}

		//供应商列表
		$supplier       = M('supplier')->field('id,name')->where(array('status'=>2))->order('sort,id')->select();
		$this->supplier = $supplier;

		$this->website_url = C('website_url');
		$this->display();
	}


	public function airplaneInfoPost()
	{
		$return    = array('valid' => false ,'state' => '操作失败');
		$id        = I('get.id');
		$productID = I('get.productID');
		if(IS_POST)
		{
			$data['productID']            = $productID;
			$data['airlineID']            = I('get.airlineID');
			$data['title']                = I('post.title');
			$data['supplierID']           = I('post.supplierID');

			$data['departurePlace']       = I('post.departurePlace');
			$data['departureAirport']     = I('post.departureAirport');
			$data['departureTime']        = strtotime(I('post.departureTime'));
			$data['departureLocalTime']   = strtotime(I('post.departureLocalTime'));

			$data['destinationPlace']     = I('post.destinationPlace');
			$data['destinationAirport']   = I('post.destinationAirport');
			$data['destinationTime']      = strtotime(I('post.destinationTime'));
			$data['destinationLocalTime'] = strtotime(I('post.destinationLocalTime'));

			$data['flightName']           = I('post.flightName');
			$data['flightNumber']         = I('post.flightNumber');
			$data['airplaneModel']        = I('post.airplaneModel');

			$data['seat']                 = I('post.seat');
			$data['status']               = '1';
			$data['sort']                 = I('post.sort',255);

			if($id)
			{
				$result = M3('product_airlineinfo_new')->where(array('id'=>$id))->save($data);
			}
			else
			{
				$result = M3('product_airlineinfo_new')->add($data);
			}

			if($result != false)
			{
				$return = array('valid' => true ,'state' => '操作成功');
			}

		}
		$this->ajaxReturn($return);
	}


	public function airplaneInfoDel()
	{
		$id     = I('get.id');

		$result = M2('product_airlineinfo_new')->where(array('id'=>$id))->save(array('status'=>'0'));

		if($result != false)
		{
			$this->success('删除航班信息成功');
		}
		else
		{
			$this->error('删除航班信息失败');
		}
		exit();
	}
	/**
	 * [destinationDataAjax description]
	 * @return [type] [description]
	 */
	public function destinationDataAjax()
	{
		$destinationID = I('post.destinationID');

		if($destinationID)
		{
			$data['destinationChildHtml'] = destinationChildHtml($destinationID);
		}

		$this->ajaxReturn($data);
	}
	/**
	 * [packCategoryAjax description]主站类型返回
	 * @return [type] [description]
	 */
	public function packCategoryAjax()
	{
		$packCategoryOne = I('get.packCategoryOne');

		$categoryArrTwo = M2('pack_product_classlabel')->where(array('pId'=>$packCategoryOne))->order('id')->select();
		$html = '';
		foreach ($categoryArrTwo as $key => $value)
		{

			$html .= '<option value="'.$value['id'].'" >'.$value['name'].'</option>';

		}
        $data['html'] = $html;
        $this->ajaxReturn($data);
	}
	/**
	 * [submitContain description]添加新增单品
	 * @return [type] [description]
	 */
	public function submitContain()
	{
		$id                = I('post.id',0);

		$add['productID'] = I('post.productID');
		$add['img']       = I('post.img');
		$add['name']      = I('post.name');
		$add['content']   = I('post.content');

		if($id == 0)
		{

			$result = M3('pack_product_contain')->add($add);
		}
		else
		{
			$result = M3('pack_product_contain')->where(array('id'=>$id))->save($add);
		}
		if($result !== false)
		{
			$data['status'] = true;
		}
		else
		{
			$data['status'] = false;
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [delContain description]新增单品删除
	 * @return [type] [description]
	 */
	public function delContain()
	{
		$id = I('get.id');

		$result = M3('pack_product_contain')->where(array('id'=>$id))->delete();
		if($result !== false)
		{
			$this->success('删除成功！');
		}
		else
		{
			$this->error('删除失败！');
		}
	}

	/**
	 * [submitGifts description]
	 * @return [type] [description]
	 */
	public function submitGifts()
	{
		$id               = I('post.id',0);

		$add['productID'] = I('post.productID');
		$add['img']       = I('post.img');
		$add['name']      = I('post.name');
		$add['price']     = I('post.price');
		$add['content']   = I('post.content');

		if($id == 0)
		{

			$result = M3('pack_product_gifts')->add($add);
		}
		else
		{
			$result = M3('pack_product_gifts')->where(array('id'=>$id))->save($add);
		}
		if($result !== false)
		{
			$data['status'] = true;
		}
		else
		{
			$data['status'] = false;
		}
		$this->ajaxReturn($data);
	}

	/**
	 * [delGifts description]
	 * @return [type] [description]
	 */
	public function delGifts()
	{
		$id = I('get.id');

		$result = M3('pack_product_gifts')->where(array('id'=>$id))->delete();
		if($result !== false)
		{
			$this->success('删除成功！');
		}
		else
		{
			$this->error('删除失败！');
		}
	}
	/**
	 * [sellRecommendSet description]
	 * @return [type] [description]
	 */
	public function sellRecommendSet()
	{
		$id   = I('get.id');
		$type = I('get.type');

		$data['recommend'] = $type;
		$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);
		if($result !== false)
		{
			$this->success('成功！');
		}
		else
		{
			$this->error('失败！');
		}
	}

	/**
	 * [sellStatusSet description]
	 * @return [type] [description]
	 */
	public function sellStatusSet()
	{
		if(IS_POST)
		{
			$id              = I('post.id');
			$data['status']  = I('post.status');
			$data['endDate'] = strtotime(I('post.endDate'));
		}

		if(IS_GET)
		{
			$id             = I('get.id');
			$data['status'] = I('get.status');
		}

		$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);
		if($result != false)
		{
			$this->success('修改状态成功！');
		}
		else
		{
			$this->error('修改状态失败！');
		}
		exit;
	}
	/**
	 * [categoryLabelList description]主站分类标签列表
	 * @return [type] [description]
	 */
	public function categoryLabelList()
	{
		$id = I('get.id');

		$list = M2('pack_product_classlabel')->where(array('pId'=>$id))->select();
		$html = '';
		$html .= '<ul>';
		foreach ($list as $key => $value)
		{
          $html .= '<li style="position: relative;display: block; min-width: 60px; height: 24px;">';
          $html .= '<input type="checkbox" style="position: absolute; min-width: 60px; height: 24px;  margin-right: 20px; opacity: 0; z-index: 99999;" name="categorylabel[]" value="'.$value['id'].'" onclick="currLabel(this)">';
          $html .= '<span style="position: absolute; display: block; text-align: center; min-width: 60px; height: 24px;  top:0px; right: 0px; bottom: 0px; left: 0px; margin: auto; cursor: pointer; background-color: #CCC; color: #FFF; line-height: 24px; z-index: 1; ">'.$value['name'].'</span>';
          $html .= '</li>';
		}
        $html .= '</ul>';
		$data['html'] = $html;
		$this->ajaxReturn($data);
	}
	/**
	 * [submitAddProduct description]附加产品添加和修改
	 * @return [type] [description]
	 */
	public function submitAddProduct()
	{

		$id               = I('post.id',0);

		$add['productID'] = I('post.productID');
		$add['img']       = I('post.img');
		$add['name']      = I('post.name');
		$add['price']     = I('post.price');
		$add['sumType']   = I('post.sumType');
		$add['price']     = I('post.price');
		$add['content']   = I('post.content');

		if($id == 0)
		{

			$result = M3('pack_addproduct')->add($add);
		}
		else
		{
			$result = M3('pack_addproduct')->where(array('id'=>$id))->save($add);
		}
		if($result !== false)
		{
			$data['status'] = true;
		}
		else
		{
			$data['status'] = false;
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [delAddProduct description]附加产品删除
	 * @return [type] [description]
	 */
	public function delAddProduct()
	{
		$id = I('get.id');

		$result = M3('pack_addproduct')->where(array('id'=>$id))->delete();

		if($result !== false)
		{
			$this->success('成功！');
		}
		else
		{
			$this->error('失败！');
		}
	}

	/**
	 * [sellrecommend description]
	 * 首页推荐管理
	 * @return [type] [description]
	 */
	public function sellrecommend()
	{
		$list = M2('pack_category_recommend_info')->order('id')->select();
		foreach ($list as $key => $value)
		{
			$list[$key]['title'] = M2('pack_product')->where(array('id'=>$value['productID']))->getField('title');
			$list[$key]['categoryName'] = M2('pack_recommend_category')->where(array('id'=>$value['categoryID']))->getField('name');
		}
		$this->list     = $list;
		$this->menuID   = '78';
		$this->menuName = '首页推荐管理';
		$this->display();
	}

	/**
	 * [sellrecommendadd description]
	 * 推荐产品添加
	 * @return [type] [description]
	 */
	public function sellrecommendadd()
	{
		if(IS_POST)
		{
			$data['productID']   = I('post.productID');
			$data['categoryID']  = I('post.categoryID');
			$data['description'] = I('post.description');
			// var_dump($data);exit;
			$result = M3('pack_category_recommend_info')->add($data);
			if($result !== false)
			{
				$this->success('添加成功！',U(MODULE_NAME. '/Product/sellrecommend'));
			}
			else
			{
				$this->error('添加失败！');
			}
			exit;
		}
		$categoryList       = M2('pack_recommend_category')->select();

		$this->categoryList = $categoryList;
		$this->menuID       = '78';
		$this->menuName     = '推荐产品添加';
		$this->display();
	}

	/**
	 * [sellrecommendcategoryadd description]
	 * @return [type] [description]
	 */
	public function sellrecommendcategoryadd()
	{
		if(IS_POST)
		{
			$data['name']  = I('post.name');
			$data['color'] = I('post.color');
			$data['img']   = I('post.img');
			$data['sort']  = I('post.sort');


			$result = M3('pack_recommend_category')->add($data);
			if($result != false)
			{
				$this->success('添加成功！',U(MODULE_NAME. '/Product/sellrecommend'));
			}
			else
			{
				$this->error('添加失败！');
			}
			exit;
		}

		$this->menuID   = '78';
		$this->menuName = '推荐分类添加';
		$this->display();
	}
	/**
	 * [productData description]
	 * @return [type] [description]
	 */
	public function productData()
	{
		$id = I('post.id');
		$data['title'] = M2('pack_product_travel')->where(array('id'=>$id))->getField('title');
		if($data['title'] != false)
		{
			$data['msg'] = true;
		}
		else
		{
			$data['msg'] = false;
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [sellrecommendedit description]
	 * @param  string $value [description]
	 * @return [type]        [description]
	 */
	public function sellrecommendedit()
	{
		$id                  = I('post.id');
		$data['productID']   = I('post.productID');
		$categoryName        = I('post.categoryName');
		$data['description'] = I('post.description');
		$productID   = M2('pack_product_travel')->where(array('id'=>$data['productID']))->getField('id');
		if($productID != false)
		{

			$categoryID = M2('pack_recommend_category')->where(array('name'=>$categoryName))->getField('id');
			if($categoryID != false)
			{
				$data['categoryID'] = $categoryID;

				$result = M3('pack_category_recommend_info')->where(array('id'=>$id))->save($data);
				if($result != false)
				{
					$data['msg'] = true;
				}
				else
				{
					$data['msg'] = '修改失败';
				}
			}
			else
			{
				$data['msg'] = '没有找到填写的类名';
			}
		}
		else
		{
			$data['msg'] = '没有找填写的产品';
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [sellrecommenddel description]
	 * @return [type] [description]
	 */
	public function sellrecommenddel()
	{
		$id = I('get.id');

		$result = M3('pack_category_recommend_info')->where(array('id'=>$id))->delete();

		if($result != false)
		{
			$this->success('删除成功！',U(MODULE_NAME. '/Product/sellrecommend'));
		}
		else
		{
			$this->error('删除失败！');
		}
	}

	/**
	 * [sellrecommendcategorylist description]
	 * @return [type] [description]
	 */
	public function sellrecommendcategorylist()
	{
		$list           = M2('pack_recommend_category')->select();

		$this->list     = $list;
		$this->menuID   = '78';
		$this->menuName = '推荐产品分类列表';
		$this->display();
	}

	/**
	 * [sellrecommendcategoryedit description]
	 * @return [type] [description]
	 */
	public function sellrecommendcategoryedit()
	{
		$id       = I('get.id');
		$this->id = $id;
		if(IS_POST)
		{
			$data['name']  = I('post.name');
			$data['img']   = I('post.img');
			$data['color'] = I('post.color');
			$data['sort']  = I('post.sort');
			$result = M3('pack_recommend_category')->where(array('id'=>$id))->save($data);

			if($result != false)
			{
				$this->success('修改成功！',U(MODULE_NAME. '/Product/sellrecommendcategorylist'));
			}
			else
			{
				$this->error('修改失败！');
			}
			exit;
		}
		$category       = M2('pack_recommend_category')->where(array('id'=>$id))->find();
		$this->category = $category;
		$this->menuID   = '78';
		$this->menuName = '推荐产品分类修改';
		$this->display();
	}

	/**
	 * [sellrecommendcategorydel description]
	 * @return [type] [description]
	 */
	public function sellrecommendcategorydel()
	{
		$id = I('get.id');

		$result = M3('pack_recommend_category')->where(array('id'=>$id))->delete();

		if($result != false)
		{
			$this->success('删除成功！',U(MODULE_NAME. '/Product/sellrecommendcategorylist'));
		}
		else
		{
			$this->error('删除失败！');
		}
	}

	/**
	 * [sellcategoryedit description]
	 * @return [type] [description]
	 */
	public function sellcategoryedit()
	{
		$id         = I('get.id');
		$this->id   = $id;

		if(IS_POST)
		{
			$data['name']     = I('post.name');
			$data['describe'] = I('post.describe');
			$data['sort']     = I('post.sort');
			$result = M3('pack_product_classlabel')->where(array('id'=>$id))->save($data);

			if($result != false)
			{
				$this->success('修改成功！',U(MODULE_NAME. '/Product/sellcategory'));
			}
			else
			{
				$this->error('修改失败！');
			}
			exit;
		}

		$list = M3('pack_product_classlabel')->where(array('id'=>$id))->find();

		$this->list     = $list;
		$this->menuID   = '77';
		$this->menuName = '直销产品'.$typeName.'修改';
		$this->display();
	}
	/**
	 * [sellproductdel description]直销产品删除
	 * @return [type] [description]
	 */
	public function sellproductdel()
	{
		$id     = I('get.id');
		$result = M3('pack_product_travel')->where(array('id'=>$id))->delete();
		if($result != false)
		{
			//产品表cms_product->cms_pack_product
			//产品详情cms_product_detail->cms_pack_product_detail
			//产品亮点cms_product_highlight->cms_pack_product_highlight
			//产品行程cms_product_travelreference->cms_pack_product_travelreference
			//产品出行日期cms_departure_time->cms_pack_departuredate
			//产品航班cms_airplane->cms_pack_airplane
			//产品酒店cms_hotel_manage->cms_pack_hotel_manage
			//棉签妹推荐表cms_pack_recommend_reson
			//包含单品表cms_pack_product_contain
			//赠送单品表cms_pack_product_gifts

			M3('pack_product_detail')->where(array('productID'=>$id))->delete();
			M3('pack_product_highlight')->where(array('productID'=>$id))->delete();
			M3('pack_product_travelreference')->where(array('productID'=>$id))->delete();
			M3('pack_departuredate')->where(array('pid'=>$id))->delete();
			M3('pack_airplane')->where(array('pid'=>$id))->delete();
			M3('pack_hotel_manage')->where(array('pid'=>$id))->delete();
			M3('pack_recommend_reson')->where(array('productID'=>$id))->delete();
			M3('pack_product_contain')->where(array('productID'=>$id))->delete();
			M3('pack_product_gifts')->where(array('productID'=>$id))->delete();
			M3('pack_addproduct')->where(array('productID'=>$id))->delete();

			$this->success('删除成功！');
		}
		else
		{
			$this->error('删除失败！');
		}
	}

	/**
	 * [localtravel description]
	 * 当地游产品列表
	 * @return [type] [description]
	 */
	public function localtravel()
	{
		$where         = array();
		$keyword       = I('get.keyword');
		$status        = I('get.status','全部');
		$where['type'] = '2';
		if($status != '全部')
		{
			$where['status'] = $status;
		}

		$this->status = $status;

		$keyword = trimall($keyword);

        if(!empty($keyword))
		{
			if(eregi('^[0-9]*$',$keyword))
			{
				$where['id'] = array('eq',$keyword);
			}
			else
			{
				$where['title'] = array('like',"%$keyword%");
			}
		}

		$count     = M2('pack_product_travel')->where($where)->count();
		$PageClass = new \Think\Page($count,10);
		$page      = $PageClass->show();
		$list      = M2('pack_product_travel')->where($where)->limit($PageClass->firstRow.','.$PageClass->listRows)->order('id DESC')->select();
		foreach($list as $key => $value)
		{

			$categoryParentName = M2('pack_product_category')->where(array('id'=>$value['categoryParentID']))->getField('categoryName');
			$categoryChildName  = M2('pack_product_category')->where(array('id'=>$value['categoryChildID']))->getField('categoryName');
			$list[$key]['categoryName'] = $categoryParentName.'/'.$categoryChildName;
			$list[$key]['supplierName'] = M('supplier')->where(array('id' => $value['supplierID']))->getField('name');
		}
		$this->keyword  = $keyword;
		$this->page     = $page;

		$this->list     = $list;
		$this->menuID   = '80';
		$this->menuName = '当地有产品列表';
		$this->display();
	}

	/**
	 * [localtravel description]
	 * 当地游产品添加
	 * @return [type] [description]
	 */
	public function localtraveladd()
	{

		if(IS_POST)
		{
			$data['title']              = I('post.title');
			$data['categoryInterestID'] = implode('|', I('post.catID',array()));
			$data['verify']             = I('post.verify',1);
			$data['extend']             = I('post.extend');
			$data['areaID']             = I('post.areaID');
			$data['countryID']          = I('post.countryID');
			$data['categoryChildID']    = I('post.packCategoryTwo');
			$data['categoryLabelID']    = implode('|', I('post.categorylabel',array()));
			$data['cityID']             = I('post.cityID');
			$data['categoryParentID']   = I('post.categoryID');
			$data['departureDate']      = I('post.departureDate');
			$data['travelDays']         = I('post.travelDays');
			$data['travelNight']        = I('post.travelNight');
			$data['marketPrice']        = I('post.marketPrice');
			$data['price']              = I('post.price');
			$data['litPic']             = I('post.litPic');
			$data['bigPic']             = I('post.bigPic');
			$data['mobileBigPic']       = I('post.mobilebigPic');
			$data['keyWords']           = I('post.keyWords');
			$data['type']               = '2';
			$data['dateLine']           = time();
			$data['adduserID']          = getIdenty();

			$productID = M3('pack_product_travel')->add($data);
			if($productID !== false)
			{
				//产品亮点
				for ($i=0; $i < 4; $i++)
				{
					$highlightData['productID'] = $productID;
					$highlightData['sort'] = $i+1;
					M3('pack_product_highlight')->add($highlightData);
				}

				//费用说明
				//预订须知
				//温馨提示
				$detailData['productID'] = $productID;
				M3('pack_product_detail')->add($detailData);

				$this->success('添加产品成功！',U(MODULE_NAME. '/Product/sell'));
			}
			else
			{
				$this->error('添加产品失败！');
			}
			exit;

		}

		//所属兴趣分类
		$catArr       = M2('product_category')->where(array('isshow'=>'1'))->order('id,sort')->select();
		$this->catArr = $catArr;

		//主站分类
		//分类标签
		$categoryArr       = M2('pack_product_category')->where(array('pId'=>'0'))->select();
		$this->categoryArr = $categoryArr;

		//目的地
		$destinationArr    = M2('destination')->where(array('pid'=>'0'))->select();
		$this->destinationArr = $destinationArr;

		$this->menuID   = '76';
		$this->menuName = '当地有产品添加';
		$this->display();
	}

	/**
	 * [localtraveledit description]
	 * 当地游产品编辑
	 * @return [type] [description]
	 */
	public function localtraveledit()
	{
		$id         = I('get.id');
		$this->id   = $id;
		$step       = I('get.step',0);
		$this->step = $step;

		if(IS_POST)
		{
			switch ($step)
			{
				case '0':
					$data['title']              = I('post.title');
					$data['categoryInterestID'] = implode('|', I('post.catID',array()));
					$data['verify']             = I('post.verify',1);
					$data['extend']             = I('post.extend');
					$data['areaID']             = I('post.continent',array())['0'];
					$data['countryID']          = I('post.country',array())['0'];
					$data['cityID']             = I('post.city',array())['0'];
					$data['categoryParentID']   = I('post.categoryID');
					$data['categoryChildID']    = I('post.packCategoryTwo');
					$data['categoryLabelID']    = implode('|', I('post.categorylabel',array()));
					$data['departureDate']      = I('post.departureDate');
					$data['travelDays']         = I('post.travelDays');
					$data['travelNight']        = I('post.travelNight');
					$data['marketPrice']        = I('post.marketPrice');
					$data['price']              = I('post.price');
					$data['litPic']             = I('post.litPic');
					$data['bigPic']             = I('post.bigPic');
					$mobilebigPic               = I('post.mobilebigPic',0);
					$data['keyWords']           = I('post.keyWords');
					if($mobilebigPic != false)$data['mobileBigPic'] = $mobilebigPic;


					$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);


					break;
				case '1':
					$content     = I('post.content',array());
					$reson       = I('post.reson',array());
					$highlightID = I('post.highlightID',array());
					$count = count($content);
					for ($i=0; $i < $count; $i++)
					{
						$data['content'] = $content[$i];
						$data['reson']   = $reson[$i];
						$result = M3('pack_product_highlight')->where(array('id'=>$highlightID[$i],'productID'=>$id))->save($data);
					}
					break;
				case '2':
					$data['costInclude'] = I('post.costInclude', '', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$id))->save($data);
					break;
				case '3':
					$data['reservationNotice'] = I('post.reservationNotice', '', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$id))->save($data);
					break;
				case '4':
					$data['warmReminder'] = I('post.warmReminder', '', 'trim');
					$result = M3('pack_product_detail')->where(array('productID'=>$id))->save($data);
					break;
				case '5':
					$data['coupon'] = implode('|', I('post.coupon',array()));
					$result = M3('pack_product_travel')->where(array('id'=>$id))->save($data);
					break;
				case '6':
					$data['recommend']              = I('post.recommend');
					$data['headerImg']              = I('post.headerImg');
					$data['reson']                  = I('post.reson');
					$data['recommendHotleReson']    = I('post.recommendHotleReson');
					$data['recommendAirplaneReson'] = I('post.recommendAirplaneReson');
					$find = M2('pack_recommend_reson')->where(array('productID'=>$id))->find();
					if($find == false)
					{
						$data['productID'] = $id;
						$result = M3('pack_recommend_reson')->add($data);
					}
					else
					{
						$result = M3('pack_recommend_reson')->where(array('productID'=>$id))->save($data);
					}
					break;

				default:
					# code...
					break;
			}

			if($result !== false)
			{
				$this->success('修改产品成功！');
			}
			else
			{
				$this->error('修改产品失败！');
			}
			exit;
		}


		//产品基本信息
		$product = M2('pack_product_travel')->where(array('id'=>$id,'type'=>'2'))->find();
		$this->product     = $product;

		switch ($step)
		{
			case '0':
				//产品所选兴趣分类
				$catCheckArr = explode('|', $product['categoryInterestID']);
				//所属兴趣分类
				$catArr       = M2('product_category')->where(array('isshow'=>'1'))->order('id,sort')->select();
				foreach ($catArr as $key => $value)
				{
					if(in_array($value['id'],$catCheckArr) == true)
					{
						$catArr[$key]['checked'] = 'checked';
					}
				}
				$this->catArr = $catArr;
				//主站分类

				$categoryOneArr = M2('pack_product_category')->where(array('pId'=>'0'))->select();
				$categoryHtmlOne = '';
				$categoryHtmlOne .= '<select name="categoryID" onchange="packCategory(this)">';
				$categoryHtmlOne .= '<option value="0">请选择</option>';
				foreach ($categoryOneArr as $key => $value)
				{
					if($value['id'] == $product['categoryParentID'])
					{
						$categoryHtmlOne .= '<option value="'.$value['id'].'" selected >'.$value['categoryName'].'</option>';
					}
					else
					{
						$categoryHtmlOne .= '<option value="'.$value['id'].'" >'.$value['categoryName'].'</option>';
					}
				}
				$categoryHtmlOne .= '</select>';
				$this->categoryHtmlOne = $categoryHtmlOne;

				$categoryTwoArr = M2('pack_product_category')->where(array('pId'=>$product['categoryParentID']))->select();

				$categoryHtmlTwo = '';
				$categoryHtmlTwo .= '<select name="packCategoryTwo" onchange="categoryLabelList(this)">';
				$categoryHtmlTwo .= '<option value="0">请选择</option>';
				foreach ($categoryTwoArr as $key => $value)
				{
					if($value['id'] == $product['categoryChildID'])
					{
						$categoryHtmlTwo .= '<option value="'.$value['id'].'" selected >'.$value['categoryName'].'</option>';
					}
					else
					{
						$categoryHtmlTwo .= '<option value="'.$value['id'].'" >'.$value['categoryName'].'</option>';
					}
				}
				$categoryHtmlTwo .= '</select>';
				$this->categoryHtmlTwo = $categoryHtmlTwo;


				//主站分类标签
				$categorylabel = explode('|', $product['categoryLabelID']);

				$categorylabelArr = M2('pack_product_categorylabel')->field('id,labelName')->where(array('categoryId'=>$product['categoryChildID']))->select();
				$categorylabelHtml = '';
				foreach ($categorylabelArr as $key => $value)
				{
					if(in_array($value['id'],$categorylabel) == true)
					{
						$categorylabelHtml .= '<input type="checkbox" name="categorylabel[]" checked value="'.$value['id'].'" style="margin-left: 10px;">'.$value['labelName'];
					}
					else
					{
						$categorylabelHtml .= '<input type="checkbox" name="categorylabel[]" value="'.$value['id'].'" style="margin-left: 10px;">'.$value['labelName'];
					}
				}
				$this->categorylabelHtml = $categorylabelHtml;

				//目的地
				$areaID    = explode(",",$product['areaID']);
				$countryID = explode(",",$product['countryID']);
				$cityID    = explode(",",$product['cityID']);

				$array_continent = M2('destination')->field('id,name')->where(array('pid'=>0))->order('sort, id')->select();
				$this->destination_continent = areaSelect('', $array_continent, "请选择大洲" );;
				$continent = '';
				foreach ($areaID as $key => $value)
				{
					$continent .= '<div><select name="continent[]" style="float:left;" onchange="destination(this,1)">';
					$continent .= areaSelect($areaID[$key], $array_continent, "请选择大洲" );
					$continent .= '</select>';
					$array_country = M2('destination')->field('id,name')->where(array('pid'=>$areaID[$key]))->order('sort, id')->select();
					$continent .= '<select name="country[]" style="float:left;" onchange="destination(this,2)">';
					$continent .= areaSelect($countryID[$key], $array_country, "请选择国家" );
					$continent .= '</select>';
					$array_city = M2('destination')->field('id,name')->where(array('pid'=>$countryID[$key]))->order('sort, id')->select();
					$continent .= '<select name="city[]" style="float:left;">';
					$continent .= areaSelect($cityID[$key], $array_city, "请选择城市" );
					$continent .= '</select>';
					$continent .= '</div>';
				}
				$this->destination = $continent;
				break;
			case '1':
				//产品亮点
				$highlight = M2('pack_product_highlight')->where(array('productID'=>$product['id']))->order('sort')->select();
				$this->highlight = $highlight;
				break;
			case '2':
				//费用包含
				$costInclude = M2('pack_product_detail')->where(array('productID'=>$product['id']))->getField('costInclude');
				$this->costInclude = $costInclude;
				break;
			case '3':
				//预订须知
				$reservationNotice = M2('pack_product_detail')->where(array('productID'=>$product['id']))->getField('reservationNotice');
				$this->reservationNotice = $reservationNotice;
				break;
			case '4':
				//温馨提示
				$warmReminder = M2('pack_product_detail')->where(array('productID'=>$product['id']))->getField('warmReminder');
				$this->warmReminder = $warmReminder;
				break;
			case '5':

				//优惠券
				$coupontypeart = M2('coupons_mould')->field('*')->order('id')->select();
				$array   = explode('|', $product['coupon']);
				foreach($coupontypeart as $key => $value)
				{
					$category = M2('coupons_category')->find($value['category_id']);
					$name = M2('coupons_cooperation')->find($value['cp_id']);
					$coupontypeart[$key]['category'] = $category['category_name'];
					$coupontypeart[$key]['name'] = $name['cooperative'];
					$coupontypeart[$key]['amount'] = $value['face_amount'];

					if(in_array($value['id'], $array))
					{
						$coupontypeart[$key]['checked'] = ' checked="checked" ';
						$coupontypeart[$key]['picture_item2'] = ' picture_item2 ';
					}

				}
				$this->coupontypelist = $coupontypeart;
				break;
			case '6':
				//棉签妹推荐
				$personRecommend = M2('pack_recommend_reson')->where(array('productID'=>$product['id']))->find();
				$this->personRecommend = $personRecommend;
				break;
			case '7':
				//包含单品
				$contain = M2('pack_product_contain')->where(array('productID'=>$product['id']))->select();
				$this->contain = $contain;
				break;
			case '8':
				//赠送单品
				$gifts = M2('pack_product_gifts')->where(array('productID'=>$product['id']))->select();
				$this->gifts = $gifts;
				break;
			default:
				//产品所选兴趣分类
				$catCheckArr = explode('|', $product['categoryInterestID']);
				//所属兴趣分类
				$catArr       = M2('product_category')->where(array('isshow'=>'1'))->order('id,sort')->select();
				foreach ($catArr as $key => $value)
				{
					if(in_array($value['id'],$catCheckArr) == true)
					{
						$catArr[$key]['checked'] = 'checked';
					}
				}
				$this->catArr = $catArr;
				//主站分类

				$categoryOneArr = M2('pack_product_category')->where(array('pId'=>'0'))->select();
				$categoryHtmlOne = '';
				$categoryHtmlOne .= '<select name="categoryID" onchange="packCategory(this)">';
				$categoryHtmlOne .= '<option value="0">请选择</option>';
				foreach ($categoryOneArr as $key => $value)
				{
					if($value['id'] == $product['categoryParentID'])
					{
						$categoryHtmlOne .= '<option value="'.$value['id'].'" selected >'.$value['categoryName'].'</option>';
					}
					else
					{
						$categoryHtmlOne .= '<option value="'.$value['id'].'" >'.$value['categoryName'].'</option>';
					}
				}
				$categoryHtmlOne .= '</select>';
				$this->categoryHtmlOne = $categoryHtmlOne;

				$categoryTwoArr = M2('pack_product_category')->where(array('pId'=>$product['categoryParentID']))->select();

				$categoryHtmlTwo = '';
				$categoryHtmlTwo .= '<select name="packCategoryTwo" onchange="categoryLabelList(this)">';
				$categoryHtmlTwo .= '<option value="0">请选择</option>';
				foreach ($categoryTwoArr as $key => $value)
				{
					if($value['id'] == $product['categoryChildID'])
					{
						$categoryHtmlTwo .= '<option value="'.$value['id'].'" selected >'.$value['categoryName'].'</option>';
					}
					else
					{
						$categoryHtmlTwo .= '<option value="'.$value['id'].'" >'.$value['categoryName'].'</option>';
					}
				}
				$categoryHtmlTwo .= '</select>';
				$this->categoryHtmlTwo = $categoryHtmlTwo;


				//主站分类标签
				$categorylabel = explode('|', $product['categoryLabelID']);

				$categorylabelArr = M2('pack_product_categorylabel')->field('id,labelName')->where(array('categoryId'=>$product['categoryChildID']))->select();
				$categorylabelHtml = '';
				foreach ($categorylabelArr as $key => $value)
				{
					if(in_array($value['id'],$categorylabel) == true)
					{
						$categorylabelHtml .= '<input type="checkbox" name="categorylabel[]" checked value="'.$value['id'].'" style="margin-left: 10px;">'.$value['labelName'];
					}
					else
					{
						$categorylabelHtml .= '<input type="checkbox" name="categorylabel[]" value="'.$value['id'].'" style="margin-left: 10px;">'.$value['labelName'];
					}
				}
				$this->categorylabelHtml = $categorylabelHtml;

				//目的地
				$areaID    = explode(",",$product['areaID']);
				$countryID = explode(",",$product['countryID']);
				$cityID    = explode(",",$product['cityID']);

				$array_continent = M2('destination')->field('id,name')->where(array('pid'=>0))->order('sort, id')->select();
				$this->destination_continent = areaSelect('', $array_continent, "请选择大洲" );;
				$continent = '';
				foreach ($areaID as $key => $value)
				{
					$continent .= '<div><select name="continent[]" style="float:left;" onchange="destination(this,1)">';
					$continent .= areaSelect($areaID[$key], $array_continent, "请选择大洲" );
					$continent .= '</select>';
					$array_country = M2('destination')->field('id,name')->where(array('pid'=>$areaID[$key]))->order('sort, id')->select();
					$continent .= '<select name="country[]" style="float:left;" onchange="destination(this,2)">';
					$continent .= areaSelect($countryID[$key], $array_country, "请选择国家" );
					$continent .= '</select>';
					$array_city = M2('destination')->field('id,name')->where(array('pid'=>$countryID[$key]))->order('sort, id')->select();
					$continent .= '<select name="city[]" style="float:left;">';
					$continent .= areaSelect($cityID[$key], $array_city, "请选择城市" );
					$continent .= '</select>';
					$continent .= '</div>';
				}
				$this->destination = $continent;
				break;
		}

		$this->website_url = C('website_url');
		$this->menuID      = '76';
		$this->menuName    = '当地有产品编辑';
		$this->display();
	}

	/**
	 * [actlist description]活动管理列表
	 * @return [type] [description]
	 */
	public function actlist()
	{
		$type       = I('get.type');
		$this->type = $type;
		$where      = array();
		switch ($type)
		{
			case '0':
				# code...
				break;
			case '1':
				$where['presellDateStart'] = array('gt',time());
				break;
			case '2':
				$where['presellDateStart'] = array('elt',time());
				$where['presellDateEnd'] = array('egt',time());
				break;
			case '3':
				$where['paymentDateStart'] = array('elt',time());
				$where['paymentDateEnd'] = array('egt',time());
				break;
			case '4':
				$where['appointmentDateStart'] = array('elt',time());
				$where['appointmentDateEnd'] = array('egt',time());
				break;
			case '5':
				$where['appointmentDateEnd'] = array('lt',time());
				break;
			default:
				# code...
				break;
		}
		$count     = M2('activity')->where($where)->count();
		$PageClass = new \Think\Page($count,10);
		$page      = $PageClass->show();
		$list      = M2('activity')->where($where)->limit($PageClass->firstRow.','.$PageClass->listRows)->order('id DESC')->select();

		foreach ($list as $key => $value)
		{
			if($value['presellDateStart'] > time())
			{
				$list[$key]['status'] = '待预售';
			}
			else if($value['presellDateStart'] <= time() && $value['presellDateEnd'] >= time())
			{
				$list[$key]['status'] = '预售中';
			}
			else if($value['paymentDateStart'] <= time() && $value['paymentDateEnd'] >= time())
			{
				$list[$key]['status'] = '支付尾款';
			}
			else if($value['appointmentDateStart'] <= time() && $value['appointmentDateEnd'] >= time())
			{
				$list[$key]['status'] = '预约中';
			}
			else
			{
				$list[$key]['status'] = '已结束';
			}
		}
		$this->page     = $page;
		$this->list     = $list;
		$this->menuID   = '87';
		$this->menuName = '活动管理列表';
		$this->display();
	}

	/**
	 * [actadd description]
	 * @return [type] [description]
	 */
	public function actadd()
	{
		if(IS_POST)
		{
			$data['title']                   = I('post.title');
			$data['presellDateStart']        = strtotime(I('post.presellDateStart'));
			$data['presellDateEnd']          = strtotime(I('post.presellDateEnd'));
			$data['presellDateFullPrice']    = I('post.presellDateFullPrice',0);
			$data['paymentDateStart']        = strtotime(I('post.paymentDateStart'));
			$data['paymentDateEnd']          = strtotime(I('post.paymentDateEnd'));
			$data['presellDatePaymentPrice'] = I('post.presellDatePaymentPrice',0);
			$data['appointmentDateStart']    = strtotime(I('post.appointmentDateStart'));
			$data['appointmentDateEnd']      = strtotime(I('post.appointmentDateEnd'));
			$data['actPic']                  = I('post.actPic');
			$result = M3('activity')->add($data);
			if($result != false)
			{
				$this->success('添加活动专题成功！',U(MODULE_NAME. '/Product/actlist'));
			}
			else
			{
				$this->error('添加活动专题失败！');
			}
			exit;
		}

		$this->menuID      = '87';
		$this->menuName    = '预售产品添加';
		$this->display();
	}
	/**
	 * [actedit description]
	 * @return [type] [description]
	 */
	public function actedit()
	{
		$id         = I('get.id');
		$this->id   = $id;
		$step       = I('get.step');
		$this->step = $step;
		if($id)
		{
			if(IS_POST)
			{
				switch ($step)
				{
					case '0':
						$data['title']                   = I('post.title');
						$data['presellDateStart']        = strtotime(I('post.presellDateStart'));
						$data['presellDateEnd']          = strtotime(I('post.presellDateEnd'));
						$data['presellDateFullPrice']    = I('post.presellDateFullPrice',0);
						$data['paymentDateStart']        = strtotime(I('post.paymentDateStart'));
						$data['paymentDateEnd']          = strtotime(I('post.paymentDateEnd'));
						$data['presellDatePaymentPrice'] = I('post.presellDatePaymentPrice',0);
						$data['appointmentDateStart']    = strtotime(I('post.appointmentDateStart'));
						$data['appointmentDateEnd']      = strtotime(I('post.appointmentDateEnd'));
						$data['actPic']                  = I('post.actPic');

						$result = M3('activity')->where(array('id'=>$id))->save($data);
						break;
					case '1':
						break;
					default:

						$data['title']                    = I('post.title');
						$data['presellDateStart']        = strtotime(I('post.presellDateStart'));
						$data['presellDateEnd']          = strtotime(I('post.presellDateEnd'));
						$data['presellDateFullPrice']    = I('post.presellDateFullPrice',0);
						$data['paymentDateStart']        = strtotime(I('post.paymentDateStart'));
						$data['paymentDateEnd']          = strtotime(I('post.paymentDateEnd'));
						$data['presellDatePaymentPrice'] = I('post.presellDatePaymentPrice',0);
						$data['appointmentDateStart']    = strtotime(I('post.appointmentDateStart'));
						$data['appointmentDateEnd']      = strtotime(I('post.appointmentDateEnd'));
						$data['actPic']                  = I('post.actPic');

						$result = M3('activity')->where(array('id'=>$id))->save($data);
						break;
				}

				if($result != false)
				{
					$this->success('修改成功！',U(MODULE_NAME. '/Product/actlist'));
				}
				else
				{
					$this->error('修改失败！');
				}
				exit;
			}

			$info             = M2('activity')->where(array('id'=>$id))->find();
			$this->info       = $info;
			$packageArr       = M2('activity_package')->where(array('activityID'=>$info['id']))->order('id')->select();
			foreach ($packageArr as $key => $value)
			{
				//套票中总分组数
				$packageArr[$key]['groupNums'] = M2('activity_package_group')->where(array('packageID'=>$value['id']))->order('id')->count();
				$groupArr                      = M2('activity_package_group')->where(array('packageID'=>$value['id']))->order('id')->select();
				foreach ($groupArr as $k => $v)
				{
					$productInfo[$key]['productArr'][$k] = M2('activity_package_group_product')->where(array('groupID'=>$v['id']))->select();
					//分组的产品数量
					$groupArr[$k]['productNums'] = count($productInfo[$key]['productArr'][$k]);
					//套票中计算总产品数
					foreach ($productInfo[$key]['productArr'] as $ki => $vi)
					{
						$packageArr[$key]['productNums'][$ki] = count($vi);
					}

					if($productInfo[$key]['productArr'][$k] == false)
					{
						$groupArr[$k]['productArr']['0'] = array('id'=>'', 'title' => '');
					}
					else
					{
						//产品标题、ID
						foreach ($productInfo[$key]['productArr'][$k] as $ki => $vi)
						{
							$groupArr[$k]['productArr'][$ki] = $productInfo[$key]['productArr'][$k][$ki];
							$groupArr[$k]['productArr'][$ki]['title'] = M2('pack_product_travel')->where(array('id'=>$vi['productID']))->getField('title');

						}
					}

				}

				//优惠券名称
				if($value['couponsID'] != false)
				{
					$listChild                       = M2('coupons_mould')->field('face_amount,cp_id')->where(array('id'=>$value['couponsID']))->find();
					$cooperative                     = M2('coupons_cooperation')->field('cooperative')->where(array('id'=>$listChild['cp_id']))->getField('cooperative');
					$packageArr[$key]['couponsName'] = $cooperative . '-【' . $listChild['face_amount']. '元】';
				}


				$packageArr[$key]['productNums'] = array_sum($packageArr[$key]['productNums']);
				$packageArr[$key]['groupArr']    = $groupArr;
			}
			$this->packageArr = $packageArr;
		}
		else
		{
			$this->redirect(MODULE_NAME. '/Product/actlist');
			exit;
		}

		$this->menuID      = '87';
		$this->menuName    = '预售产品编辑';
		$this->display();
	}

	/**
	 * [actdel description]
	 * @return [type] [description]
	 */
	public function actdel()
	{
		$id = I('get.id');
		if($id)
		{
			$result = M3('activity')->where(array('id'=>$id))->delete();
			if($result != false)
			{
				$this->success('删除成功！',U(MODULE_NAME. '/Product/actlist'));
			}
			else
			{
				$this->error('删除失败！');
			}
			exit;
		}
	}

	/**
	 * [presellDelAjax description]
	 * @return [type] [description]
	 */
	public function presellDelAjax()
	{
		$type   = I('post.type');
		$typeID = I('post.typeID');
		$pId    = I('post.pId');
		$title  = I('post.title');

		switch ($type)
		{
			case 'package':
				$result = M3('activity_package')->delete($typeID);
				break;
			case 'group':
				$result = M3('activity_package_group')->delete($typeID);
				break;
			case 'product':
				$result = M3('activity_package_group_product')->delete($typeID);
				break;
		}

		if($result == false)
		{
			$data['valid'] = false;
			$data['state'] = '删除'.$title.'失败！';
		}
		else
		{
			$data['valid'] = true;
			$data['state'] = '删除'.$title.'成功！';
		}

		$this->ajaxReturn($data);
	}
	/**
	 * [actDataAjax description]
	 * @return [type] [description]
	 */
	public function actDataAjax()
	{
		$type        = I('post.type');
		$typeID      = I('post.typeID');
		$executeType = I('post.executeType');
		$pId         = I('post.pId');
		switch ($type)
		{
			case 'package':
				$data['activityID']      = $pId;
				$data['title']           = I('post.title');
				$data['presellPrice']    = I('post.presellPrice');
				$data['paymentPrice']    = I('post.paymentPrice');
				$data['couponsID']       = I('post.couponsID');
				$data['appointmentNums'] = I('post.appointmentNums');
				switch ($executeType)
				{
					case 'add':
						$result = M3('activity_package')->add($data);
						break;
					case 'edit':
						$result = M3('activity_package')->where(array('id'=>$typeID))->save($data);
						break;
				}
				break;
			case 'group':
				$data['packageID']        = $pId;
				$data['title']            = I('post.title');
				$data['appointmentCheck'] = I('post.appointmentCheck',0);
				switch ($executeType)
				{
					case 'add':
						$result = M3('activity_package_group')->add($data);
						break;
					case 'edit':
						$result = M3('activity_package_group')->where(array('id'=>$typeID))->save($data);
						break;
				}
				break;
			case 'product':
				$data['groupID']          = $pId;
				$data['productID']          = I('post.productID');
				$data['appointmentCheck'] = I('post.appointmentCheck',0);
				switch ($executeType)
				{
					case 'add':
						$result = M3('activity_package_group_product')->add($data);
						break;
					case 'edit':
						$result = M3('activity_package_group_product')->where(array('id'=>$typeID))->save($data);
						break;
				}
				break;
		}

		if($result != false)
		{
			$data['valid'] = true;
			$data['state'] = '添加成功！';
		}
		else
		{
			$data['valid'] = false;
			$data['state'] = '添加失败！';
		}

		$this->ajaxReturn($data);
	}

	/**
	 * [productSearchAjax description]
	 * @return [type] [description]
	 */
	public function productSearchAjax()
	{
		$productID = I('post.productID');
		$title     = M2('pack_product_travel')->where(array('id'=>$productID))->getField('title');
		if($title == false)
		{
			$data['valid'] = false;
			$data['state'] = '没有查到你所查找的产品信息';
		}
		else
		{
			$data['valid'] = true;
			$data['title'] = $title;
		}

		$this->ajaxReturn($data);
	}
	/**
	 * [couponsListDataAjax description]
	 * 优惠券ajax请求列表
	 * @return [type] [description]
	 */
	public function couponsListDataAjax()
	{
		$title      = I('post.title');
		$returnData = array();
		$list       = M2('coupons_cooperation')->field('id,cooperative')->where(array('cooperative'=>array('LIKE',"%$title%")))->select();
		if($list == false)
		{
			$listChild = M2('coupons_mould')->field('id,face_amount,cp_id')->where(array('face_amount'=>array('LIKE',"%$title%")))->select();

			if($listChild == false)
			{
				$data['valid'] = false;
			}
			else
			{
				$data['valid'] = true;
				foreach ($listChild as $key => $value)
				{
					$list = M2('coupons_cooperation')->field('cooperative')->where(array('id'=>$value['cp_id']))->select();
					foreach ($list as $k => $v)
					{
						$returnData[$key][$k]['id'] = $value['id'];
						$returnData[$key][$k]['title'] = $v['cooperative'] . '-【' . $value['face_amount']. '元】';
					}
				}
			}
		}
		else
		{
			$data['valid'] = true;
			foreach ($list as $key => $value)
			{
				$listChild = M2('coupons_mould')->field('id,face_amount')->where(array('cp_id'=>$value['id']))->select();

				foreach ($listChild as $k => $v)
				{
					$returnData[$key][$k]['id'] = $v['id'];
					$returnData[$key][$k]['title'] = $value['cooperative'] . '-【' . $v['face_amount']. '元】';
				}
			}
		}

		$data['couponsData'] = $returnData;
		$this->ajaxReturn($data);
	}
	/**
	 * [visalist description]
	 * 签证产品列表
	 * @return [type] [description]
	 */
	public function visalist()
	{
		$countryID       = I('get.countryID');
		$schengen        = I('get.schengen');
		$this->countryID = $countryID;
		$this->schengen  = $schengen;

		$where           = array();
		if($schengen != false)
		{
			$where['schengenCheck'] = $schengen;
		}
		if($countryID != false)
		{
			$where['pid'] = $countryID;
		}
		else
		{
			$where['pid'] = array('neq','0');
		}
		$where['status']        = '1';
		$count                  = M2('visa_passport_type')->where($where)->count();
		$PageClass              = new \Think\Page($count,20);
		$page                   = $PageClass->show();

		$list = M2('visa_passport_type')->where($where)->limit($PageClass->firstRow.','.$PageClass->listRows)->order(array('status'=>'DESC','id'=>'DESC'))->select();
		foreach ($list as $key => $value)
		{
			$list[$key]['countryName'] = M2('visa_passport_type')->where(array('id'=>$value['pid']))->getField('name');
			switch ($value['validDateType'])
			{
				case 'D':
					$list[$key]['validDate'] = $value['validDate'] . '天';
					break;
				case 'M':
					$list[$key]['validDate'] = $value['validDate'] . '个月';
					break;
				case 'Y':
					$list[$key]['validDate'] = $value['validDate'] . '年';
					break;

				default:
					$list[$key]['validDate'] = '使馆批';
					break;
			}

			switch ($value['stopDateType'])
			{
				case 'D':
					$list[$key]['stopDate'] = $value['stopDate'] . '天';
					break;
				case 'M':
					$list[$key]['stopDate'] = $value['stopDate'] . '个月';
					break;
				case 'Y':
					$list[$key]['stopDate'] = $value['stopDate'] . '年';
					break;

				default:
					$list[$key]['stopDate'] = '使馆批';
					break;
			}

			switch ($value['entryNums'])
			{
				case '0':
					$list[$key]['entryNums'] = '使馆批';
					break;

				default:
					$list[$key]['entryNums'] = $value['entryNums'] . '次';
					break;
			}
		}
		$this->page     = $page;
		$this->list     = $list;

		$countryArr       = M2('visa_passport_type')->where(array('pid'=>'0'))->select();
		$this->countryArr = $countryArr;

		$this->menuID   = '76';
		$this->menuName = '签证产品列表';
		$this->display();
	}

	/**
	 * [visaadd description]
	 * 签证产品添加
	 * @return [type] [description]
	 */
	public function visaadd()
	{
		if(IS_POST)
		{
			$data['name']           = I('post.title');
			$data['pid']            = I('post.pid');
			$data['schengenCheck']  = I('post.schengenCheck');
			$coutryIDArr            = I('post.countryID',array());
			$data['countryID']      = implode('|',$coutryIDArr);
			$data['validDate']      = I('post.validDate');
			$data['validDateType']  = I('post.validDateType');
			$data['stopDate']       = I('post.stopDate');
			$data['stopDateType']   = I('post.stopDateType');
			$data['workDay']        = I('post.workDay');
			$data['entryNums']      = I('post.entryNums');
			$data['interviewCheck'] = I('post.interviewCheck');
			$data['costPrice']      = I('post.costPrice');
			$data['sellPrice']      = I('post.sellPrice');
			$provinceIDArr          = I('post.provinceID',array());
			$data['provinceID']     = implode('|',$provinceIDArr);
			$data['notice']         = I('post.notice');
			$data['remark']         = I('post.remark');
			$data['createTime']     = time();
			$data['status']         = '1';

			$visaProductID       = M3('visa_passport_type')->add($data);

			if($visaProductID != false)
			{
				$needData    = I('post.needData',array());
				$content     = I('post.content',array());
				$uploadPlugs = I('post.uploadPlugs',array());

				$count = count($needData);
				for ($i=0; $i < $count; $i++)
				{
					$addNeed['visaID']      = $visaProductID;
					$addNeed['title']       = $needData[$i];
					$addNeed['content']     = $content[$i];
					$addNeed['uploadPlugs'] = $uploadPlugs[$i];
					M3('visa_product_needdata')->add($addNeed);
				}

				$this->success('添加成功！',U(MODULE_NAME.'/Product/visalist'));
			}
			else
			{
				$this->error('添加失败！');
			}
			exit;
		}
		$countryArr = M2('visa_passport_type')->where(array('pid'=>'0'))->order('sort')->select();
		$countryHtml = '';
		$countryHtml .= '<select name="pid" style="margin-left: 5px;">';
		$countryHtml .= '<option value="0">请选择签证国家</option>';
		foreach ($countryArr as $key => $value)
		{
			$countryHtml .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
		}
		$countryHtml .= '</select>';
		$this->countryHtml = $countryHtml;
		$this->destinationHtml = destinationHtml('', 'areaID', '1', 'destinationSelect(this)');
		$this->provinceHtml    = provinceHtml();
		$this->menuID          = '76';
		$this->menuName        = '签证产品添加';
		$this->display();
	}

	/**
	 * [visaedit description]
	 * 签证产品编辑
	 * @return [type] [description]
	 */
	public function visaedit()
	{
		$id = I('get.id');
		$this->id = $id;
		if(IS_POST)
		{
			$data['pid']            = I('post.pid');
			$data['name']           = I('post.title');
			$data['schengenCheck']  = I('post.schengenCheck');
			$coutryIDArr            = I('post.countryID',array());
			$data['countryID']      = implode('|',$coutryIDArr);
			$data['validDate']      = I('post.validDate');
			$data['validDateType']  = I('post.validDateType');
			$data['stopDate']       = I('post.stopDate');
			$data['stopDateType']   = I('post.stopDateType');
			$data['workDay']        = I('post.workDay');
			$data['entryNums']      = I('post.entryNums');
			$data['interviewCheck'] = I('post.interviewCheck');
			$data['costPrice']      = I('post.costPrice');
			$data['sellPrice']      = I('post.sellPrice');
			$provinceIDArr          = I('post.provinceID',array());
			$data['provinceID']     = implode('|',$provinceIDArr);
			$data['notice']         = I('post.notice');
			$data['remark']         = I('post.remark');
			$data['status']         = '1';

			$result = M3('visa_passport_type')->where(array('id'=>$id))->save($data);

			if($result != false)
			{
				$needDataID  = I('post.needDataID',array());
				$needData    = I('post.needData',array());
				$content     = I('post.content',array());
				$uploadPlugs = I('post.uploadPlugs',array());

				$count = count($needData);
				for ($i=0; $i < $count; $i++)
				{
					$addNeed['title']       = $needData[$i];
					$addNeed['content']     = $content[$i];
					$addNeed['uploadPlugs'] = $uploadPlugs[$i];
					if($needDataID[$i] == false)
					{
						$addNeed['visaID'] = $id;
						M3('visa_product_needdata')->add($addNeed);
					}
					else
					{
						M3('visa_product_needdata')->where(array('id'=>$needDataID[$i]))->save($addNeed);
					}
				}

				$this->success('修改成功！',U(MODULE_NAME.'/Product/visalist'));
			}
			else
			{
				$this->error('修改失败！');
			}
			exit;

		}

		$visaProduct       = M2('visa_passport_type')->where(array('id'=>$id))->find();

		$countryIDs        = str_replace("|", ",", $visaProduct['countryID']);
		$countryArr        = M2('destination')->field('id,name')->where(array('id'=>array('IN',$countryIDs)))->select();
		$this->countryArr  = $countryArr;

		$provinceIDs       = str_replace("|", ",", $visaProduct['provinceID']);
		$provinceArr       = M2('address_province')->where(array('province_id'=>array('IN',$provinceIDs)))->select();
		$this->provinceArr = $provinceArr;

		$this->visaProduct = $visaProduct;

		$needDataArr       = M2('visa_product_needdata')->where(array('visaID'=>$id))->select();
		$this->needDataArr = $needDataArr;

		$this->destinationHtml = destinationHtml('', 'areaID', '1', 'destinationSelect(this)');

		$visaCountryArr = M2('visa_passport_type')->where(array('pid'=>'0'))->order('sort')->select();
		$countryHtml = '';
		$countryHtml .= '<select name="pid" style="margin-left: 5px;">';
		$countryHtml .= '<option value="0">请选择签证国家</option>';
		foreach ($visaCountryArr as $key => $value)
		{
			if($value['id'] == $visaProduct['pid'])
			{
				$countryHtml .= '<option value="'.$value['id'].'" selected>'.$value['name'].'</option>';
			}
			else
			{
				$countryHtml .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
			}
		}
		$countryHtml .= '</select>';
		$this->countryHtml = $countryHtml;

		$this->provinceHtml    = provinceHtml();

		$this->menuID          = '76';
		$this->menuName        = '签证产品编辑';
		$this->display();
	}

	/**
	 * [visadel description]
	 * 签证产品删除
	 * @return [type] [description]
	 */
	public function visadel()
	{
		$id             = I('get.id');
		$data['status'] = '0';
		$result         = M3('visa_product')->where(array('id'=>$id))->save($data);

		if($result != false)
		{
			$this->success('删除成功！');
		}
		else
		{
			$this->error('删除失败！');
		}
		exit;
	}
	/**
	 * [delNeedDataAjax description]
	 * @return [type] [description]
	 */
	public function delNeedDataAjax()
	{
		$id = I('post.id');
		if($id)
		{
			$result = M3('visa_product_needdata')->where(array('id'=>$id))->delete();
		}

		if($result != false)
		{
			$data['valid'] = true;
			$data['state'] = '删除成功';
		}
		else
		{
			$data['valid'] = false;
			$data['state'] = '删除失败';
		}
		$this->ajaxReturn($data);
	}
	/**
	 * [addVisaCountryAjax description]
	 *
	 */
	public function addVisaCountryAjax()
	{
		$countryName = I('post.countryName');
		if($countryName != false)
		{
			$data['name'] = $countryName;
			$data['pid']  = '0';
			$result = M3('visa_passport_type')->add($data);
			if($result != false)
			{
				$data['valid'] = true;
				$data['state'] = '添加成功';
			}
			else
			{
				$data['valid'] = false;
				$data['state'] = '添加失败';
			}
		}
		else
		{
			$data['valid'] = false;
			$data['state'] = '签证国家不能为空';
		}
		$this->ajaxReturn($data);
	}

	public function synProduct()
	{
		$where = array();
		$where['libraryID'] = array('neq',false);

		$list = M2('pack_product_travel')->where($where)->select();
		foreach ($list as $key => $value)
		{
			$list[$key]['library'] = M2('pack_product_line_library')->where(array('productID'=>$value['id']))->select();

			foreach ($list[$key]['library'] as $k => $v)
			{
				$departuredate = M2('pack_departuredate')->where(array('libraryID'=>$v['libraryID'],'pid'=>$v['productID']))->select();
				foreach ($departuredate as $ki => $vi)
				{
					$result = M2('library_time')->where(array('libraryID'=>$v['libraryID'],'departureTime'=>$vi['departuretime']))->find();
					if($result == false)
					{
						M2('pack_departuredate')->where(array('id'=>$vi['id']))->delete();
					}

				}
				unset($departuredate);

				switch ($v['gainType'])
				{
					case '0':
						$library_time = M2('library_time')->where(array('libraryID'=>$v['libraryID'],'departureTime'=>array('egt',time())))->select();
						foreach ($library_time as $ki => $vi)
						{
							if($vi['adultCostPrice'] != false)
							{
								$departureDateData['adultPrice'] = $vi['adultCostPrice'];
								$departureDateData['childPrice'] = $vi['childCostPrice'];
								$departureDateData['seat']       = $vi['stockNow'];
								M2('pack_departure_date')->where(array('libraryID'=>$v['libraryID'],'productID'=>$v['productID'],'departuretime'=>$vi['departureTime']))->save($departureDateData);
							}
						}
						break;

					case '1':
						$library_time = M2('library_time')->where(array('libraryID'=>$v['libraryID'],'departureTime'=>array('egt',time())))->select();
						foreach ($library_time as $ki => $vi)
						{
							if($vi['adultCostPrice'] != false)
							{
								$departureDateData['adultPrice'] = $vi['adultCostPrice'] + $v['gainNums'];
								$departureDateData['childPrice'] = $vi['childCostPrice'] + $v['gainNums'];
								$departureDateData['seat']       = $vi['stockNow'];
								M2('pack_departure_date')->where(array('libraryID'=>$v['libraryID'],'productID'=>$v['productID'],'departuretime'=>$vi['departureTime']))->save($departureDateData);
							}
						}
						break;
					case '2':
						$library_time = M2('library_time')->where(array('libraryID'=>$v['libraryID'],'departureTime'=>array('egt',time())))->select();
						foreach ($library_time as $ki => $vi)
						{
							if($vi['adultCostPrice'] != false)
							{
								$departureDateData['adultPrice'] = $vi['adultCostPrice'] + $vi['adultCostPrice']*$v['gainNums'];
								$departureDateData['childPrice'] = $vi['childCostPrice'] + $vi['adultCostPrice']*$v['gainNums'];
								$departureDateData['seat']       = $vi['stockNow'];
								M2('pack_departure_date')->where(array('libraryID'=>$v['libraryID'],'productID'=>$v['productID'],'departuretime'=>$vi['departureTime']))->save($departureDateData);
							}
						}
						break;
				}
				unset($library_time);
			}
		}
	}

}

/**
 * [departureHtml description]
 * @param  [type]  $departureCityIDStr [description]
 * @param  boolean $name               [description]
 * @return [type]                      [description]
 */

function departureHtml($departureCityIDStr,$name = false)
{
	$departureCityIDArr     = explode('|', $departureCityIDStr);
	$departureCityIDArrNums = count($departureCityIDArr);
	$departureCityArr       = M2('departure')->field('id,name')->order('sort')->select();
	$departureHtml          = array();
	$name = isset($name) ? $name : 'departureCityID[]';

	for ($i=0; $i < $departureCityIDArrNums; $i++)
	{
		$departureHtml[$i] = '';
		$departureHtml[$i] .= '<select name="'.$name.'">';
		$departureHtml[$i] .= '<option value="0">请选择城市</option>';
		foreach ($departureCityArr as $key => $value)
		{
			if($departureCityIDArr[$i] == $value['id'])
			{
				$departureHtml[$i] .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
			}
			else
			{
				$departureHtml[$i] .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
			}
		}
		$departureHtml[$i] .= '</select>';
	}

	return $departureHtml;
}
/**
 * [destinationHtml description]
 * @return [type] [description]
 */
function destinationHtml($destinationID, $name = false, $deep = '1', $function = false)
{
	$destinationPID = M2('destination')->where(array('id'=>$destinationID))->getField('pid');
	$destinationPID = isset($destinationPID) ? $destinationPID : '0';
	$destinationArr = M2('destination')->where(array('pid'=>$destinationPID))->order('sort')->select();
	switch ($deep)
	{
		case '1':
			$htmlName = '大洲';
			$name = isset($name) ? $name : 'areaID[]';
			break;
		case '2':
			$htmlName = '国家';
			$name = isset($name) ? $name : 'countryID[]';
			break;
		case '3':
			$htmlName = '城市';
			$name = isset($name) ? $name : 'cityID[]';
			break;
		default:
			$htmlName = '大洲';
			$name = isset($name) ? $name : 'areaID[]';
			break;

	}

	$destinationHtml = '';
	$destinationHtml .= '<select name="'.$name.'" onChange="'.$function.'" >';
	$destinationHtml .= '<option value="0">请选择'.$htmlName.'</option>';
	foreach ($destinationArr as $key => $value)
	{
		if($destinationID == $value['id'])
		{
			$destinationHtml .= '<option value="'.$value['id'].'" selected >'.$value['name'].'</option>';
		}
		else
		{
			$destinationHtml .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
		}
	}
	$destinationHtml .= '</select>';

	return $destinationHtml;
}

/**
 * [destinationChildHtml description]
 * @return [type] [description]
 */
function destinationChildHtml($destinationID)
{
	$destinationArr = M2('destination')->where(array('pid'=>$destinationID))->select();

	$destinationHtmlOption = '';
	foreach ($destinationArr as $key => $value)
	{
		$destinationHtmlOption .= '<option value="'.$value['id'].'">'.$value['name'].'</option>';
	}

	return $destinationHtmlOption;
}
/**
 * [provinceHtml description]
 * @return [type] [description]
 */
function provinceHtml()
{
	$provinceArr = M2('address_province')->order('province_id')->select();
	$provinceHtml = '';
	$provinceHtml .= '<select name="provinceID" >';
	$provinceHtml .= '<option value="0">请选择省份</option>';
	foreach ($provinceArr as $key => $value)
	{
		$provinceHtml .= '<option value="'.$value['province_id'].'">'.trim($value['province_name']).'</option>';
	}
	$provinceHtml .= '</select>';

	return $provinceHtml;
}


function productLabelHtml()
{

	$labelClassArr = M2('label_class')->where(array('pid'=>'0'))->select();
	$labelClassHtml = '';
	$labelClassHtml .= '<select name="productLabelClassID" onchange="getLabel(this)">';
	$labelClassHtml .= '<option value="0">全部标签</option>';
	foreach ($labelClassArr as $key => $value)
	{
		$labelClassHtml .= '<option value="'.$value['id'].'">'.trim($value['name']).'</option>';
	}
	$labelClassHtml .= '</select>';

	return $labelClassHtml;

}

?>